def Alex(): a = 5 while True: f = (yield a) # yield a and possibly get f in return if f is not None: a = f # store the new value g = Alex() print g.next() print g.next() print g.send(34) print g.next() # now it will yield 34 until we send something else a = [1,2,3,4,5] print a[::2] print a[::-1] def jamie(): x = 45 while True: u = (yield x) # yield x and possibly get u in return if u is not None: x = u print 34/356.0 print g.next()/2.0 print 2/3.14159265358979 print 22/7 print 355/113.0 print 'knock knock' print 'who is there?' print 'doctor' print 'doctor who?' print 'pi = 3.1415' # Of course there is more def function()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question