Python笔记 基础篇

for循环

lst = [1, 2, 3, 4, 5]
for i in lst:
    print(i)

while

def func(max):
    n = 0
    while True:
        n = n + 1
        if n > max:
            break
    
        print(n)

func(10)

条件语句

def func(is_rish_man):
    if is_rish_man:
        print('打工是不可能打工的,这辈子都不可能打工')
    else:
        print('真香')

func(False)
def func(age):
    if  0 < age < 18:
        print('未成年人')
    elif age >= 18:
        print('成年人')
    else:
        print('?')

func(25)
Comments
Write a Comment