Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
cyanly6413yYeah, one of these things making me want to KMS every time those Quant traders pass over a zip folder “here’s the new code, you guys can productionise it” Whoever had this idea making Python defacto “Data Scientists” language should _____ ____ themselves...
Pick Ruby instead 😊
spky4233yWell, not sloppy, but consequent.
Consider this: A scope in python is anything which is at the same indent or any indent more on the right.. (think of nested blocks)
> if True:
> x = 23
> # x is valid here
> # but not here
Now the twist: The for loop does two things at the same time: Declaring a variable and opening a new block.
Because the for loop itself is part of the outer block, the variable is declared there and will also be available in the outer block.
I feel this is the most logical behavior, never had any issues with it.
Try not to use single character variable names, and while you’re on it, do yourself a favor and use Python 3.
Python 2 is (very soon) unsupported, and contains many illogical pitfalls..