Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Basic] Indentation
#2
What's with the quote?

Also something notable about indentation - I've heard braces in C/C++/Java compared to indentation in Python, but there is a vital difference. In the aforementioned languages, you can simply add braces to denote a new scope. This is rarely used, but Python is different in an important way - as mentioned above, you can't just indent without good reason, but also, scope is not denoted by indentation. A variable created within an indented block will "leak" into the enclosing space, as in a for loop. Functions, classes and modules are the ways to create new scopes, and even though two of those use indentation, indentation itself does not generally create scope.


Messages In This Thread
Indentation - by metulburr - Sep-01-2016, 08:16 PM
RE: Indentation basic - by micseydel - Oct-03-2016, 07:14 PM
RE: Indentation - by metulburr - Oct-21-2017, 12:28 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020