Python Syntax
Python Syntax compared to other programming languages
Python was designed to for readability, and has some similarities to the English language with influence from mathematics.
Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.
Python Indentations
Where in other programming languages the indentation in code is for readability only, in Python the indentation is very important.
Python uses indentation to indicate a block of code.
Python will give you an error if you skip the indentation.
Comments
Python has commenting capability for the purpose of in-code documentation.
Comments start with a #
, and Python will render the rest of the line as a comment:
Docstrings
Python also has extended documentation capability, called docstrings.
Docstrings can be one line, or multiline. Docstrings are also comments:
Python uses triple quotes at the beginning and end of the docstring:
References
Last updated