解包、递归

 1 解包
 2 msg = 'admin,123456'
 3 # msg1 = {}
 4 # username = msg.split(',')[0]
 5 # password = msg.split(',')[1]
 6 username,password = msg.split(",")  #只针对list和tuple及str
 7 # msg1[username] = password
 8 # print(msg1)
 9 print(username,password)
10 
11 msg2 = {"username":"admin","password":"123456"}
12 # print(msg2.items())
13 for k,v in msg2.items():
14     print(k,v)
15 
16 
17 递归
18 # 函数自己调用自己,就是递归
19 
20 # def test():
21 #     print('5.1快乐')
22 #     test() #自己调用自己  死循环
23 #
24 #
25 # test()
26 
27 # def test():
28 #     number = int(input("请输入一个数字").strip())
29 #     if number % 2== 0:
30 #         print("输入正确")
31 #         return
32 #     test()   #输入错误的话一直调用直到正确为止
33 #
34 # test()
35 
36 def replace(src,old,new):
37     if old in src:
38         return new.join(src.split(old))
39     return src
40 
41 a = "abc,abc,sdgsd"
42 b = "123"
43 c = "你好"
44 
45 result = replace(a,b,c)
46 print(result)
47  

 

posted @ 2021-05-13 17:59  等待iing  阅读(62)  评论(0)    收藏  举报