Instructions that a Python interpreter execute are called statements. For example, x = 1 is an assignment statement. pass statement ,if statement, for statement, while statement etc.
A statement extend over multiple lines with the line continuation character (\). For example:
4 + 5 + 6 + \
7 + 8 + 9
Python IndentationPython uses indentation to define block e.g body of a function, class ,loop etc. starts with indentation and ends with the first unindented line. Generally four whitespaces are used for indentation and is preferred over tabs. Here is an example.
Comments allows to describe the code details that might help for reading/ enhancing or debuuging the code.
- In Python, hash (#) symbol is used for writing a comment.
- It extends up to the newline character.
- Comments enhaces the readability of a program.
- Python Interpreter ignores comment.
We can also use triple quotes, either ''' or """ for multi line comments. These triple quotes are generally used for multi-line strings. But they can be used as multi-line comment as well. Unless they are not docstrings, they do not generate any extra code.
Docstring is short for documentation string. It is a string that occurs as the first statement in a module, function, class, or method definition. The docstring describes what a function/class does in the docstring. Triple quotes are used while writing docstrings. For example: