Created
September 24, 2018 09:15
-
-
Save lxfly2000/4a4ab4ed18bb39044b1008a1eb4dbd48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding=utf-8 | |
#Python 生成器的应用 | |
#把普通的遍历完后产生返回的集合对象过程(整体返回)改为一边遍历一边返回集合中对象的过程(交错返回) | |
def GetSomeNumbers(stopTag): | |
if stopTag==0: | |
print("遍历所有数值") | |
if stopTag==1: | |
return | |
yield 213 | |
yield 271 | |
if stopTag==2: | |
return | |
yield 12450 | |
if stopTag==3: | |
return | |
yield 114514 | |
yield 1919 | |
yield 810 | |
if stopTag==4: | |
return | |
yield 12450 | |
def main(): | |
print("生成器:") | |
for n in GetSomeNumbers(0): | |
print(n) | |
listNumbers={1,1,4,5,1,4,1,9,1,9,8,1,0} | |
print("数组列表:") | |
for m in listNumbers: | |
print(m) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment