摘要: def print_paras(fpara, *nums, **words): print("fpara: " + str(fpara)) print("nums: " + str(nums)) print("words: " + str(words)) print_paras("hello", 1, 3, 5, 7, word="python", anohter_w... 阅读全文
posted @ 2017-12-22 23:52 雷大侠! 阅读(229) 评论(0) 推荐(0) 编辑
摘要: # 默认参数 def repeat_str(s, times = 1): repeated_strs = s * times return repeated_strs repeated_strings = repeat_str("Happy Birthday!") print(repeated_strings) repeated_strings_2 = repeat... 阅读全文
posted @ 2017-12-22 20:17 雷大侠! 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 输出: 阅读全文
posted @ 2017-12-22 19:47 雷大侠! 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 键(key),对应值(value) 在我们不确定字典中是否存在某个键而又想获取其值时,可以使用get方法,还可以设置默认值: >>> age = info.get('age') >>> age #'age'键不存在,所以age为None >>> type(age) >>> age = info.get('age', 18) # 若info中不存在'age'这个键,就返回默认值18 >>> ... 阅读全文
posted @ 2017-12-22 17:29 雷大侠! 阅读(197) 评论(0) 推荐(0) 编辑
摘要: #创建只有一个元素的tuple,需要用逗号结尾消除歧义 a_tuple = (2,) #tuple中的list mixed_tuple = (1, 2, ['a', 'b']) print("mixed_tuple: " + str(mixed_tuple)) mixed_tuple[2][0] = 'c' mixed_tuple[2][1] = 'd' print("mixed_tup... 阅读全文
posted @ 2017-12-22 17:26 雷大侠! 阅读(567) 评论(0) 推荐(1) 编辑
摘要: # 一、创建元组 # tup1 = ('physics', 'chemistry', 1997, 2000) # tup2 = (1, 2, 3, 4, 5 ) # tup3 = "a", "b", "c", "d" # 元组中只包含一个元素时,需要在元素后面添加逗号来消除歧义 # tup1 = (50,) # 二、访问元组 tup1 = ('physics', 'chemistry', 199... 阅读全文
posted @ 2017-12-22 17:23 雷大侠! 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 输出结果 阅读全文
posted @ 2017-12-22 16:29 雷大侠! 阅读(232) 评论(0) 推荐(0) 编辑