标签:时间 bre pre time ble object cti 创建 except
列表生成式
[x*2 for x in range(10)]
生成器(generator object)
1,(x*2 for in in range(10)) >>>generator object
2,def f():
yield
f()>>>> generator object
生成器的方法
1> next(f()) >>>计算出一个值
注意:生成器再创建时,已经决定了能计算出的值的个数。调用next()的次数超个这个值就会包StopIteration
遍历所有元素可以通过FOR 循环
for i in [1,2,3]:
print(i)
for 循环内部做了三件事:
1, 调用对象的iter()方法,返回一个迭代器对象
2, while:
try:
i = netex(list_Itertor
except StopIteration: 3 朴拙异常
break
2> send()
f().send(None) # 等同于next(f())
迭代器
满足迭代器协议:
1,内部有next 方法
2,内部有iter()方法
li = [1,2,3] :Iterble (内部有iter方法)
>>>i = iter(li).list_Itertor
接着可以使用next(i)
time
time.time()
time.strtime()
time.gmtime(): >>>UTC时间
time.localtime(): >>本地时间
time.ctime()
datetime
detetime.datetime.now()
random
chr()
标签:时间 bre pre time ble object cti 创建 except
原文地址:https://www.cnblogs.com/my-python-road/p/10540534.html