#!/usr/bin/env python
# -*- conding: UTF -*-
'''使用yield中途停止,之后继续执行。有点像中断的意思'''
from random import randint
def simpleGen():
yield 1
yield '2 -->punch!'
def randGen(aList):
while len(aList) > 0:
yield aList.pop(randint(0,len(aList)-1))
这里写代码片
for eachItem in simpleGen():
print eachItem
for item in randGen(['rock', 'paper', 'acissors']):
print item
输出:
D:\Python27\test>func25.py
1
2 -->punch!
paper
acissors
rock
D:\Python27\test>