Collection of common code usage methods

1. The return statement is used to exit the function and return an expression to the caller . When the return statement is executed, the function will exit, and the statement after the return will not be executed. like:

def my_print(x):
    if x == 1:
        return False
    print('i am xiao ming')
    return True


a = my_print(1)   # 满足if,执行return False,不再执行之后的语句,跳出函数。
print(a)

# 输出:False

Guess you like

Origin blog.csdn.net/Wzongming/article/details/128019790