python
笔记
map
函数用于读取一行多组数据:
#读取列表
list = list( map(int,input().split('')) )
#解压列表
x,y,z = map(int,input().split(''))
- 深拷贝和浅拷贝
x=y[:]
a=[1,2] b=[3,4]
y=[a,b]
#深拷贝#
x=y #x,y相当于一个指针 x改变会改变y的值
x[1]='abc' >>> y=['abc',[3,4]]
#浅拷贝#
x=y[:] #x复制y 单独作为一个列表存在
-
字符串不能改变:
a='abc' a[0]='b'
报错 -
range(begin,end,公差)
生成列表:list( range(10) )
-
函数传参:函数内变量修改 不会影响函数外 而传入数组会 既类似于引用
函数用法
- 遍历且修改集合的内容
users = {'Hans': 'active', 'Éléonore': 'inactive', 'jeck': 'active'}
#第一种 copy
for user, status in users.copy().items():
if status == 'inactive':
del users[user]
#第二种 creat new
active_users = {}
for user, status in users.items():
if status == 'active':
active_users[user] = status