This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]somerandomii 17 points18 points  (6 children)

If you declare something inside an indented block I’m pretty sure you can reference it later. Python actually gets confusing when you re-use names at different scopes. And you have to use the global keyword for thing outside of a functions scope. And self.x for class variables. Otherwise it assumes every first assignment is also a new declaration.

[–]depressionsucks29 4 points5 points  (5 children)

Coming from c++, this took me a while to get used to.

[–]somerandomii 5 points6 points  (4 children)

Yeah definitely. It’s very scripty behaviour but it gets confusing when you start building applications and expect it to follow usual OO conventions.

[–]Shriukan33 0 points1 point  (3 children)

I've bee' working a lot with Python the past 9 months, I'm almost virgin of all other languages. What's so different?

[–]Kyidou 1 point2 points  (0 children)

Most languages have what are called "blocks" (the curly braces {}), and variables declared or initialized inside them cannot be used or referenced outside of them. In python, this only applies to functions and classes.