Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Miika Vuorio
3,579 Pointsif a variable is redefined inside the scope of an if statement will it affect the variable outside of it's scope.
And how about loops or anything else. Also if not then how to make it so that it does.
1 Answer
Steven Parker
243,318 PointsPython doesn't create separate block scopes (as some other languages do), so conditionals and loops operate in the same scope that they occur in.
Python has separate scopes for modules, classes, functions generator expressions, and list comprehensions.