Detailed introduction to if statement in python

不言
Release: 2019-03-09 14:11:15
forward
4213 people have browsed it

This article brings you a detailed introduction to the if statement in python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

input() gets the string. bool: Only empty values ​​are False, any characters are True

elif

If it is a multi-condition branch, different conditions will execute differently, use The format of elif
is as follows:

if 条件1
	执行代码1
elif 条件2
	执行代码2
elif 条件3
	执行代码3
.......
else
	以上条件都不满足执行代码
Copy after login

can be regarded as a code block from if to elif to else and the indented code below it.

if nested

  • elif, multiple conditions, each condition is level
  • The nesting of if is progressive . When meets the condition , add another branch
    Syntax format:
if 条件1:
	if 条件2:
		执行
	else 不满足条件2:
		执行
else 不满足条件1:
	执行
Copy after login

pycharm Tips: Select multiple lines and press Tab to add indentation in front of each line, and then press Shift Tab to cancel the indentation

The above is the detailed content of Detailed introduction to if statement in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!