自定义函数: def myfun(args1,args2): 函数体 return value
代码语言:javascript复制def get_info():
userinfo = {}
with open("info.txt","r",encoding="utf-8") as f:
lines = f.readlines()
for line in lines:
line = line.strip()
line = line.split(" ")
#print(line[0])
if not(line[0] == ''):
userinfo[line[0]] =line[1]
else:
pass
#print("读取到空行")
return userinfo
调用函数:
代码语言:javascript复制get_info()
递归调用:0
代码语言:javascript复制def move(rank,s1,s2,s3):
if(rank == 1):
print("移动%d盘子%c到%c",rank,s1,s3)
else:
move(rank-1,s1,s3,s2)
print("移动%d盘子%c到%c", rank, s1, s3)
move(rank-1,s2,s1,s3)
move(3, 'A', 'B', 'C')