python 使用for 实现死循环

code

import time

#——————————————————————————————————————————————
#死循环打印1
'''
def count_n1():
    return 1

for i in iter(count_n1, 6):
    print(i)

'''

#——————————————————————————————————————————————
#打印
# 1
# 2
# 3
# 4
# 5

n=0

def count_n2():
    global n
    n=n+1
    return n

for i in iter(count_n2, 6):
    print(i)

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2020-08-23 23:39  anobscureretreat  阅读(3878)  评论(0编辑  收藏  举报