只能使用 if ... elif ... else 多分支语句,或者使用 if 语句的嵌套没有else if语法,只有elif语法
if 表达式1 : 语句块1 elif 表达式2: 语句块2 ... else: 语句块NPython 中没有do…while循环
可以使用while 循环一般为了防止死循环:
none = True while none: ... if 条件: none = FalsePython 中的for循环
1.语法
for 迭代变量 in 对象 : 循环体
2.range( )函数
range(start,end,step)
说明:
start : 计数的起始值,如果省略,默认从0开始end :若括号内仅一个参数,则默认为end。比如range(7)代表0,1,2,3,4,5,6,不含7step :若括号内有两个参数,则默认为start和end。用于指定步长,即两个数之间的间隔。又如range(1,7)得到1,2,3,4,5,6。
3. for循环遍历字符串
string = '画里出尘,水滨思远人' print(string) for ch in string: print(ch) for ch in string: print(ch,end = ' ')



