day3 python函数

发布时间:2019-09-24 08:26:54编辑:auto阅读(1723)

    自定义函数:
    def myfun(args1,args2):
    函数体
    return value

    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

    调用函数:

    get_info()

    递归调用:0

    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')

关键字