PI. More then one value on return

Run Settings
LanguagePython
Language Version
Run Command
# So, lets here make more attention on yield statement. def fib(n=0): a, b = 0, 1 i = 0 while not n or n < a: # Returning multiple values is not just power of yield, return key-word # could be here as well, here we just reemploy known code for explanation. yield i, b a, b, i = b, a + b, i + 1 res = "" # See here, we're obtaining both of them into actual values of for statement # and then operate together. for n, f in fib(): if n > 10 or f > 100: break res += " " + str(f) print res # Here's an example of simpler code without for-loop statement on how to operate # with multiple return. import random def randomDucks(): n = random.randint(1, 30) return n, ["duck"] * n number, ducks = randomDucks() print number print ducks
Editor Settings
Theme
Key bindings
Full width
Lines