变量
name = “jiangshuai”#全局变量,在程序范围内生效
school = “high school”
def change_name(name):
global school#字符串和整数的全局变量不能再函数里修改,列表、字典、集合可以修改
print(“before change”,name,school)
school = “University”
name = “alex”#局部变量,这个函数就是这个变量的作用域
print(“after change”,name,school)
change_name(name)
print(name,school)
递归
#递归必须要有明确结束条件
#每递归一次问题规模都应该减少
#最大递归上线为999
def calc(n):
print(n)
if int(n/2)>0:
return calc(int(n/2))
print("->",n)
calc(10)