一枝恋、指定長度數(shù)組
[0] * 10
二练链、減少加法運(yùn)行速度,可以用內(nèi)置函數(shù)庫
sum(range(1,100000000))
三先壕、字典的合并
1.
dict1 = {"one": 1, "two": 2, "three": 3}
dict2 = {"four": 4, "five": 5}
dict1.update(dict2)
print(dict1)
2.
print(dict(dict1, **dict2))
四瘩扼、版本
import sys
s = sys.version
print(s[:5], type(s))
五、魔法方法
print(random.__all__)
__name__
__doc__
六垃僚、構(gòu)造字典列表
list1 = [1, 2, 3, 4, 5]
list2 = [5, 6, 7, 8, 9]
list3 = [7, 8, 9, 1, 2]
z1 = zip(list1, list2)
z2 = zip(list3, z1)
print(dict(z2))
七集绰、tuple比list效率高,list比set效率高
八谆棺、星的用法
dict1 = {"one": 1, "two": 2, "three": 3}
def fun(x, y, z):
print(x * 3, y, z)
fun(*dict1)
九栽燕、字典函數(shù)
dict1 = {
"addxy": lambda x, y: x + y,
"mulxy": lambda x, y: x * y
}
print(dict1["mulxy"](20, 20))