摘要: 集合:对应数学中的集合类型。集合中的元素是唯一,且无序的。 创建集合 方法一:使用{},注意python会自动删除重复元素 方法二:使用set()工厂函数,传递一个列表,元组或字符串 访问集合元素 方法一:使用for把集合中元素一个一个读出来 方法二:使用in和not in来判断一个元素是否在集合中 阅读全文
posted @ 2017-10-31 23:02 去伪存真 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 字典:是python中唯一的映射类型,字典中每一项都是由键-值对组成的项。字典中没有索引,只有键和值。键的类型可以是整型,变量或字符串。 创建和访问字典: 1 >>> dict1 = {'Lining':'Anything is possible', 'Nike':'Just do is', 'Ad 阅读全文
posted @ 2017-10-31 22:45 去伪存真 阅读(283) 评论(0) 推荐(0) 编辑
摘要: lambda表达式: 用法 lambda x : 2 * x + 1 其中:前面是参数,后面是返回值。 1 >>> def ds(x): 2 ... return 2 * x + 1 3 ... 4 >>> ds(5) 5 11 6 >>> lambda x : 2*x+1 7 <function 阅读全文
posted @ 2017-10-31 21:04 去伪存真 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 牛刀小试: 定义一个无参函数 1 >>> def myFirstFunc(): 2 ... print("Hello python") 3 ... print("hello world") 4 ... print("hello my fist func") 5 ... 6 >>> myFirstFu 阅读全文
posted @ 2017-10-31 20:28 去伪存真 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 之前学习的列表,元组,字符串都是序列类型,有很多共同特点: 序列通用BIF介绍 例子 1 >>> number = [3, 1,6,8,4,5] 2 >>> number 3 [3, 1, 6, 8, 4, 5] 4 >>> max(number) 5 8 6 >>> min(number) 7 1 阅读全文
posted @ 2017-10-31 16:51 去伪存真 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 格式化字符串,可以使用format方法。format方法有两种形式参数,一种是位置参数,一种是关键字参数。 1 >>> '{0} {1}'.format('Hello', 'Python') #位置参数 2 'Hello Python' 3 >>> '{a} python {b} world'.fo 阅读全文
posted @ 2017-10-31 16:34 去伪存真 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 定义字符串 1 >>> mystring = 'Hello Python' 2 >>> name = str('Mountain') 3 >>> mystring 4 'Hello Python' 5 >>> name 6 'Mountain' 通过索引或字符串切片可以访问字符串 1 >>> for 阅读全文
posted @ 2017-10-31 15:29 去伪存真 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 元组:和列表十分相似,可以说是一个受限的列表。最大的限制是,元组不能更改。 创建元组 1 >>> tuple1 = (123,'asd',(1,2,3)) 2 >>> tuple1 3 (123, 'asd', (1, 2, 3)) 访问元组 通过索引或元组切片访问元组 1 >>> for i in 阅读全文
posted @ 2017-10-31 00:49 去伪存真 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 列表:是一个加强版的数组,什么东西都可以往里面放。 创建列表 创建一个普通列表: 1 >>> member = ['operating system', 'data structure', 'network', 'principle of computer composition'] 2 >>> m 阅读全文
posted @ 2017-10-31 00:35 去伪存真 阅读(307) 评论(0) 推荐(0) 编辑