Statement
What is a Statement in Python?
In Python, a statement
refers to an instruction which the Python interpreter can execute. As a programming language, Python is an unambiguous set of instructions for completing a task, and each of these instructions is known as a statement.
Various types of Python statements include:
- Assignment Statements
- Conditional Statements
- Loop Statements
- Import Statements
Assignment Statements
Assignment statements
are used to (re)bind names to values and also modify attributes or items of mutable objects. In simple terms, they are used to define a variable and associate a value with it.
Conditional Statements
Conditional statements
, also known as selection statements, allow the execution of a statement sequence based on the evaluation of a condition. The if
, elif
and else
statements are the most common types of conditional statements in Python.
Loop Statements
Loop statements
are used to repeatedly execute a block of statements as long as the condition remains true. for
and while
are the most common loop statements.
Import Statements
The import statement
is used to include external modules into a Python script. When included, the functions and classes defined in the module can be used in the current script.
Note
In Python, the end of a statement is marked by a newline character. However, we can make a statement extend over multiple lines with the line continuation character (\
), or by using parentheses, brackets, or braces.