statement
In Python, a statement is a complete instruction that tells the interpreter to perform an action. Unlike expressions which produce values, statements execute operations or control program flow. Every line of executable code in Python is a statement, though some statements can span multiple lines.
Some statements contain expressions (such as assignments or function calls), while others control program structure (like if
or while
blocks). The key distinction is that statements perform actions rather than just evaluating to values.
Key Characteristics
- Performs an action or controls program flow
- Typically occupies one or more complete lines
- Does not necessarily produce a value
- Can contain expressions as components
Examples
x = 5 # Assignment statement
print("Hello") # Function call statement
if x > 0: # Compound statement
print("Positive") # Nested statement
return x + y # Return statement
Related Resources
Tutorial
Expression vs Statement in Python: What's the Difference?
In this tutorial, you'll explore the differences between an expression and a statement in Python. You'll learn how expressions evaluate to values, while statements can cause side effects. You'll also explore the gray areas between them, which will enhance your Python programming skills.
For additional information on related topics, take a look at the following resources: