【python] Python的那些妙事
python 动态创建类
type('Hello', (object,), dict())
set 集合
& 交集
| 并集
^ 补集
- 差集
built-in 函数
- breakpoint()
相当于pdb断点 - divmod()
divmod(4,2) # (2,0)
divmod(x,y) 可代替 (x//y, x%y)
iter() 迭代器妙用
itr = iter('abcd')
if 'c' in itr:
print(next(itr)) # d
chain 函数
参数带* 与不带*
import itertools
a= ['a','aa','aaa']
b= itertools.chain(a)
c= itertools.chain(*a)
print(a)
print(list(b))
print(list(c))
# [‘a’, ‘aa’, ‘aaa’]
# [‘a’, ‘aa’, ‘aaa’]
# [‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’]

浙公网安备 33010602011771号