Python 高级用法记录
优雅的 Python 代码,高级的使用技巧
小技巧
- 省略号
…
可以代替pass
,同时还是 Numpy 的一个语法糖
# ...也是一个Python对象
def func():
...
def func():
pass
-
sum()
函数计算可迭代对象(例如列表、元组或集合)中所有数值的总和,还可以连接多个列表。
>>> a = [1,2]
>>> b = [3,4]
>>> c = [5,6]
>>>
>>> Sum(a, start=10) # 提供可选的 start 参数,以将数字添加到总和
13
>>> sum((a,b,c), [])
[1, 2, 3, 4, 5, 6]
- 用
_
辅助标识,可以使大数变得更易于阅读
>>> number=123_456_789
>>> number
281028344
Enjoy Reading This Article?
Here are some more articles you might like to read next: