Does Python have blockscoping?

We all know that Python treats blocks a little differently than { curly bracketed } languages like C or C++

But it actually treats them a lot differently. Example below shows

# python scoping
x = 5
if x is 5:
  print 'x is 5'
  y = 1000
else:
  print 'x is not 5'
  y = 19

print y  # see 1000, no errors.

# conclusion:  python does not have block scope.
# but i'm not one to rely on it.

Post a Comment