1. python不支持类型: char
2. 字符视为长度为1的字符串
3. 字典中的键:要求为不可变的对象
4.python 2.X中 print type(1/2) <type'int'>
python 3.x中 print(type(1/2)) <type'float'>
5. math.floor(x): 不大于x的最大值,向下取整
6. extend()与append()的区别:
append()方法例子
s =[1,2] s.append([3,4]) print(s) print(len(s))
执行结果:
extend()方法例子
s =[1,2] s.extend([3,4]) print(s) print(len(s))
执行结果:
7. 浅拷贝 copy()与深拷贝 deepcopy()
7.1 字典数据类型的copy函数,当简单的值替换的时候,原始字典和复制过来的字典之间互不影响,但是当添加,删除等修改操作的时候,两者之间会相互影 响
替换值示例:
1 import copy 2 one ={'name':['Anna','hobby']} 3 two = one.copy() 4 three = copy.deepcopy(one) 5 one['name']=['anna'] 6 print(one) 7 print(two) 8 print(three) 9 10 执行结果 11 12 {'name': ['anna']} 13 {'name': ['Anna', 'hobby']} 14 {'name': ['Anna', 'hobby']}
添加值示例:
1 import copy 2 one ={'name':['Anna','hobby']} 3 two = one.copy() 4 three = copy.deepcopy(one) 5 one['name'].append('becky') 6 print(one) 7 print(two) 8 print(three) 9 10 11 执行结果 12 13 {'name': ['Anna', 'hobby', 'becky']} 14 {'name': ['Anna', 'hobby', 'becky']} 15 {'name': ['Anna', 'hobby']}
7.2 copy包中的copy函数,无论是修改还是值替换两者之间都互不影响
1 import copy 2 li = [1,2,3] 3 li1 = li 4 li2 = copy.copy(li) 5 li3 = copy.deepcopy(li) 6 li.append(5) 7 li2[2]=6 8 print(li,li1,li2,li3) 9 10 执行结果: 11 12 [1, 2, 3, 5] [1, 2, 3, 5] [1, 2, 6] [1, 2, 3]
8. 列表去重方法,如:[3,4,2,2,4,3]
简单方法:list(set([3,4,2,2,4,3]))