首页 > 编程语言 >Python学习笔记(四)

Python学习笔记(四)

时间:2022-11-21 20:55:06浏览次数:37  
标签:语句 ... end statement2 statement1 Python 笔记 else 学习

控制语句

条件控制结构

在python中,实现条件控制的语句是if...else语句。

if(条件):
    语句块
else:
    语句块

Python没有强制要求条件加上括号,但最好还是加上吧。

 

跟c一样,if...else语句可以有单分支,多分支或者嵌套结构。但是没有类似c中的switch语句。

#Single branch

if(condition):
    statement1
    statement2
    ...
#end if

#Multiple branch
if(condition1):
    statement1
    statement2
    ...
elif(condition2):
    statement1
    statement2
    ...
else:
    statement1
    statement2
    ...
#end if...else

#Nested form
if(condition1):
    statement
    ...
    if(condition2):
        statement
        ...
    else:
        statement
        ...
    #end inside if...else
else:
    statement
    ...
#end if...else

 

循环控制结构

标签:语句,...,end,statement2,statement1,Python,笔记,else,学习
From: https://www.cnblogs.com/haibersut/p/16913193.html

相关文章