摘要:
#传参列表副本(不改变列表本身) lst = [1, 5, 33, 58] def func(a): a[0] = 99 print(a) print(lst) #[1, 5, 33, 58] func(lst[:]) #不改变lst, [99, 5, 33, 58] func(lst.copy()) #不改变lst, ... 阅读全文
摘要:
#传参: 字典/键值对 def func(**kvargs): print('解包字典:') for k, v in kvargs.items(): print('{}:{}'.format(k, v)) #传键值对 func( name= 'Tom', age = 20) #传字典 employee = dict(name = 'Tom', age = 2... 阅读全文
摘要:
#计算平均值(可变参数) def avg_numberic(a, *args): return (a + sum(args)) / (len(args) + 1) print('计算平均值, 结果 = {}'.format(avg_numberic(1, 2, 3, 4, 5))) t = (50, 40, 30 ,20) print('元组解包, 计算平均值, 结果 = {}'.f... 阅读全文
摘要:
打印结果:key = namekey = agekey = salaryvalues = Tomvalues = 20values = 8800.0name:Tomage:20salary:8800.0 阅读全文
摘要:
#遍历列表, 打印索引和元素 names = ['Tom', 'Jerry', 'Marry'] for index, name in enumerate(names): print('names[{}] = {}'.format(index, name)) 打印结果: names[0] = Tom names[1] = Jerry names[2] = Ma... 阅读全文
摘要:
工具 -> 编译系统 -> 新编译系统 { "cmd": ["python","-u","$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "encoding": "cp936" } 用上面的代码替换掉"sh... 阅读全文