零基础学习01(条件,循环和其他语句 )
一.print和import更多信息
1.使用逗号输出
打印多个表达式,将它们用逗号隔开

2.赋值魔法
多个赋值

交换变量

链式赋值

增量赋值

二.条件和条件语句
1.if语句和else,elif
if语句,当if后面的表达式为真时执行
a=int(input(‘input num:’))
if a=2:
print ('this is 2')
else子句,之所以叫做子句是因为它不能单独存在,依赖if语句
a=int(input(‘input num:’))
if a=2:
print ('this is 2')
else:
print ('this is not 2')
如果需要检查多个条件,就可以使用elif,它是else if的缩写。要和if else 联合使用
a=int(input(‘input num:’))
if a=2:
print ('this is 2')
elif a=0:
print ('this is 0')
else:
print ('this is not 2')
它们之间还可以嵌套使用
下面的值作为布尔表达式时都不被看做假(false)
false None 0 '' () [] {}
2.更复杂的条件




三.循环
1.while循环
打印1-100

就像上面这样,不是很复杂吧?
while语句非常灵活。它可以用来在任何条件为真的情况下重复执行。
2.for循环

打印1-100
for i in range(1,101):
print (i)<em><br /></em> for 更简洁,能用for尽量不用while,它容易造成死循环。<br /><strong> 3.退出循环<br /></strong>break语句用来终止循环语句<br /><strong> <br /></strong>continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮循环。<br /><strong> <br /></strong><em> <br /></em>
相关推荐
机器之心 2020-11-17
quanquanxiu 2020-06-12
yuanshuai 2020-06-12
lei0 2020-06-10
加油奋斗吧 2020-06-02
lgblove 2020-05-06
Dablelv 2020-04-19
文山羊 2020-04-08
付春杰Blog 2020-03-04
paopao00 2020-02-11
sschencn 2019-12-27
typhoonpython 2019-12-17
sschencn 2019-12-05
Wonder的学习 2019-12-03
woodenrobot 2019-08-23
平凡的程序员 2019-11-05
hnyzyty 2019-11-04