>>> fruits = ["apple", "banana", "cherry"] >>> for x in fruits: ... print(x) ... if x == "banana": ... print(y) ... if x == "apple": ... y=1 ... apple banana 1 cherry
Probably you don't like the "hoisting" of the binding of y?
Please note that JS is also doing hoisting even that it has a var statement°
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
°) and now even let which behaves (almost completely) like my in Perl
In reply to Re^7: Nesting Functions
by LanX
in thread Nesting Functions
by betmatt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |