流程语句

 

1. 运算符

比较运算符    ==, !=,>, <, >=, <= 

+=, -=,  *= , /= , %= ,  **= , //=

i*=10-3+8   ->i=i+10-3+8

i+=1; 没有i++

str+=''

num=random.randint(0,2)   0,1,2

逻辑运算符   or  ,  and 

类型转换:int(input('请输入'))

print('hello ',end='')   python3

2. 条件

age = 20

if age>=10:

  print('年龄大于等于10')

elif age <20 and age>10

  print('....')

if 10<20:
    print('hello ')
    if 20<10:
        print('world')
        print('....')
    else:
        print('')
    print('end...')
else:
    print('else')

条件的False有:False, None, ''

e.g    

c = False
if not c:
    print('c is false')
a = ''
if not a:
    print('a is false')
b = None
if not b:
    print('b is false')
# 如果or的前面是false(False、None 或 ''),表达式为后面的值
print(False or 'hello')  # hello
print('' or 'hello')  # hello
print(None or 'hello')  # hello

三元表达式:str = 'hello' if Trure else ''

3. while

while true:

  print('   ')

4.for

name='zhangsan'
for a in name:
    print(a)
原文地址:https://www.cnblogs.com/zhuxiang1633/p/8846998.html