python控制结构有:for循环, while循环, if条件语句,下面我们直接上代码。
一、for循环
a = range(5) for x in a : print(x)
0 1 2 3 4
二、while循环
a = [1, 2, 3, 4, 5] print(a) while len(a) > 0 : a.pop(); print(a)
[1, 2, 3, 4, 5] [1, 2, 3, 4] [1, 2, 3] [1, 2] [1] []
三、if条件语句
a = '1' b = 1 if type(a) != type(b) : print('a type:', type(a)) print('b type:', type(b)) else : print('a type is same as b type')
a type: <class 'str'> b type: <class 'int'>
OK, 本讲到此结束,后续更多精彩内容,请持续关注我的博客。
浙公网安备 33010602011771号