- Why does Python use indentation for grouping of statements?
- ===========================================================
- Guido van Rossum believes that using indentation for grouping is
- extremely elegant and contributes a lot to the clarity of the average
- Python program. Most people learn to love this feature after a while.
- Since there are no begin/end brackets there cannot be a disagreement
- between grouping perceived by the parser and the human reader.
- Occasionally C programmers will encounter a fragment of code like
- this:
- if (x <= y)
- x++;
- y--;
- z++;
- Only the "x++" statement is executed if the condition is true, but the
- indentation leads many to believe otherwise. Even experienced C
- programmers will sometimes stare at it a long time wondering as to why
- "y" is being decremented even for "x > y".
- Because there are no begin/end brackets, Python is much less prone to
- coding-style conflicts. In C there are many different ways to place
- the braces. After becoming used to reading and writing code using a
- particular style, it is normal to feel somewhat uneasy when reading
- (or being required to write) in a different one.
- Many coding styles place begin/end brackets on a line by themselves.
- This makes programs considerably longer and wastes valuable screen
- space, making it harder to get a good overview of a program. Ideally,
- a function should fit on one screen (say, 20--30 lines). 20 lines of
- Python can do a lot more work than 20 lines of C. This is not solely
- due to the lack of begin/end brackets -- the lack of declarations and
- the high-level data types are also responsible -- but the indentation-
- based syntax certainly helps.
- Python IndentationError: unexpected indent (How to Fix This Stupid Bug)
- https://www.youtube.com/watch?v=ceDih3Mb5yE
- Also see:
- Should you use TABS or SPACES for indentation in Python?
- https://www.youtube.com/watch?v=hCLf6cNYnCk
- [embed]
Python software and documentation are licensed under the PSF License Agreement.
Starting with Python 3.8.6, examples, recipes, and other code in the documentation are dual licensed under the PSF License Agreement and the Zero-Clause BSD license.
Some software incorporated into Python is under different licenses. The licenses are listed with code falling under that license. See Licenses and Acknowledgements for Incorporated Software for an incomplete list of these licenses.
Python and it's documentation is:
Copyright © 2001-2022 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com. All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.
See History and License for complete license and permissions information:
https://docs.python.org/3/license.html#psf-license