摘要: Python是一门解释型语言! 解释型优点:有良好的平台兼容性,在任何环境中都可以运行,前提是安装了解释器(虚拟机)。灵活,修改代码的时候直接修改就可以,可以快速部署,不用停机维护。缺点:每次运行的时候都要解释一遍,性能上不如编译型语言。 变量定义的规则: 变量名只能是 字母、数字或下划线的任意组合 阅读全文
posted @ 2017-12-24 23:44 雷大侠! 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 孙子曰: 地形有通者、有挂者、有支者、有隘者、有险者、有远者。我可以往,彼可以来,曰通。通形者,先居高阳,利粮道,以战则利。可以往,难以返,曰挂。挂形者,敌无备,出而胜之,敌若有备,出而不胜,难以返,不利。我出而不利,彼出而不利,曰支。支形者,敌虽利我,我无出也,引而去之,令敌半出而击之利。隘形者, 阅读全文
posted @ 2017-12-23 22:29 雷大侠! 阅读(1114) 评论(0) 推荐(0) 编辑
摘要: '''示例1: 最简单的函数,表示调用了两次''' def myfunc(): print("myfunc() called.") myfunc() myfunc() # 第二步:使用装饰函数在函数执行前和执行后分别附加额外功能 # '''示例2: 替换函数(装饰) # 装饰函数的参数是被装饰的函数对象,返回原函数对象 # 装饰的实质语句: myfunc = deco(myfu... 阅读全文
posted @ 2017-12-23 14:53 雷大侠! 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑