🏢 Corporate Training Programs — Customized for Your Organization Get a Demo
🎯 95% Placement Rate — Start Your Career in AI, 5G & Telecom View Success Stories
🚀 New Batch Starting This Month — Limited Seats Available Enroll Now
Back to Blog General

Python Statements

Super Admin · November 3, 2026 · 8 min read
Python Statements

Python Statements: A Complete Beginner's Guide With Examples

Python statements are instructions that Python executes to perform operations such as assigning values, displaying information, making decisions, repeating tasks, and defining functions.

Every Python program consists of statements arranged to achieve a particular objective.

Understanding statements is essential because they form the building blocks of Python applications.

In this tutorial, you will learn what Python statements are, the difference between simple and compound statements, how statements work, and how to use them in practical programs.

What Is a Python Statement?

A Python statement is an instruction that forms part of a program.

For example:

print("Welcome to Python")

Output:

Welcome to Python

This statement calls the built-in print() function to display text.

Consider another example:

age = 20

This is an assignment statement. It assigns the integer value 20 to the variable age.

Python programs combine different types of statements to process information and control execution.

Types of Python Statements

At a beginner level, Python statements can be grouped into two broad categories:

  1. Simple statements

  2. Compound statements

This is a useful introductory classification. Python's formal grammar contains additional distinctions, but these two categories help explain the fundamentals.

1. Simple Statements

A simple statement is generally written on a single logical line.

Examples include assignment statements, function calls, import statements, and return statements.

Example 1: Assignment Statement

name = "Amit"
age = 22

These statements assign values to variables.

The first statement assigns a string to name, while the second assigns an integer to age.

Example 2: Print Statement

print("Hello, Python!")

Output:

Hello, Python!

The statement calls the print() function.

In Python 3, print is a function, not a print statement as it was in Python 2.

Example 3: Import Statement

import math

print(math.sqrt(64))

Output:

8.0

The import statement makes the math module available to the program.

The program then calls math.sqrt() to calculate the square root of 64.

Example 4: Multiple Simple Statements on One Line

Python allows simple statements to be separated by semicolons on the same physical line.

x = 10; y = 20; print(x + y)

Output:

30

Although this is valid, using separate lines is usually clearer:

x = 10
y = 20

print(x + y)

Output:

30

2. Compound Statements

A compound statement contains a header and a body.

The body usually consists of one or more statements arranged in an indented block.

Common compound statements include:

  • if, elif, and else

  • for

  • while

  • def

  • class

  • try

  • with

These statements are used to control program flow, define reusable code, and organize operations.

Example 1: The if Statement

The if statement executes a block when a condition evaluates to true.

age = 20

if age >= 18:
    print("You are eligible to vote.")

Output:

You are eligible to vote.

The condition age >= 18 evaluates to True, so Python executes the indented statement.

If the condition is false, the body of this if statement is skipped.

Example 2: The if...else Statement

The if...else statement provides two alternative execution paths.

number = 7

if number % 2 == 0:
    print("Even number")
else:
    print("Odd number")

Output:

Odd number

The % operator returns the remainder after division.

Because 7 % 2 equals 1, the condition is false and the else block executes.

Example 3: The for Loop

A for loop can iterate over items in a sequence or other iterable object.

for number in range(1, 6):
    print(number)

Output:

1
2
3
4
5

The range(1, 6) expression produces the integers from 1 through 5.

The loop executes the indented print() statement once for each value.

Example 4: The while Loop

A while loop repeatedly executes its body while its condition remains true.

count = 1

while count <= 3:
    print("Count:", count)
    count += 1

Output:

Count: 1
Count: 2
Count: 3

Let's understand the program:

  1. count begins with the value 1.

  2. Python checks whether count <= 3.

  3. If the condition is true, the body executes.

  4. count += 1 increases the value by one.

  5. The condition is checked again.

The loop terminates when count becomes 4.

Important: A while loop must have an appropriate termination condition or another way to exit. Otherwise, it may run indefinitely.

3. Python Statements for Defining Functions

A function is a reusable block of code that can be called when needed.

The def keyword introduces a function definition.

Example

def greet():
    print("Welcome to Python!")

greet()

Output:

Welcome to Python!

The first part defines the function named greet.

The final statement calls the function, causing its body to execute.

Example: A Function With Parameters

def add_numbers(a, b):
    result = a + b
    print("Sum:", result)

add_numbers(10, 20)

Output:

Sum: 30

The function receives two arguments, adds them, and displays the result.

Function definitions make programs easier to organize and reuse.

4. Python Statements for Returning Values

The return statement is used inside a function to return a value to the caller.

Example

def multiply(a, b):
    return a * b

result = multiply(5, 4)

print(result)

Output:

20

The function calculates the product and returns it.

The returned value is then assigned to result and displayed.

A return statement also ends the execution of the current function.

5. Python Statements for Loop Control

Python provides break, continue, and pass for different purposes.

The break Statement

The break statement immediately terminates the nearest enclosing loop.

Example:

for number in range(1, 6):
    if number == 4:
        break

    print(number)

Output:

1
2
3

When number becomes 4, the break statement terminates the loop.

The continue Statement

The continue statement skips the remaining statements in the current loop iteration and moves to the next iteration.

Example:

for number in range(1, 6):
    if number == 3:
        continue

    print(number)

Output:

1
2
4
5

The number 3 is not displayed because its iteration is skipped.

The pass Statement

The pass statement performs no operation. It can be used as a placeholder where Python requires a statement syntactically.

Example:

for number in range(1, 4):
    if number == 2:
        pass

    print(number)

Output:

1
2
3

The pass statement does not skip the iteration or terminate the loop. Execution continues to the next statement.

6. Python Statements for Handling Errors

The try...except compound statement allows a program to handle specified exceptions.

Example

try:
    number = int("abc")
    print(number)
except ValueError:
    print("The input is not a valid integer.")

Output:

The input is not a valid integer.

Python cannot convert the string "abc" into an integer, so int() raises a ValueError.

The except block handles that exception and displays a message.

Error handling can help programs respond more gracefully to invalid input and other expected failures.

7. Python Statements for Importing Modules

The import statement allows you to use functionality provided by modules.

Example

import random

number = random.randint(1, 10)

print(number)

Possible output:

7

The output may differ because random.randint(1, 10) generates a random integer between 1 and 10, inclusive.

Import statements are useful when working with Python's standard library and third-party packages.

8. Difference Between Simple and Compound Statements

The following table summarizes the main differences.

Note: A function call is a type of expression used as a simple statement when it is written as an expression statement. The distinction between statements and expressions is important: an expression produces a value, while a statement performs an instruction in the program.

9. Practical Example: Combining Python Statements

Let's build a simple program that checks whether a student has passed an examination.

The passing mark is 40.

student_name = input("Enter student name: ")
marks = int(input("Enter marks: "))

if marks >= 40:
    result = "Pass"
else:
    result = "Fail"

print("Student:", student_name)
print("Marks:", marks)
print("Result:", result)

Example Interaction

Enter student name: Rahul
Enter marks: 75
Student: Rahul
Marks: 75
Result: Pass

How Does This Program Work?

Step 1: Assignment and input

The input() function reads the student's name and marks. The int() function converts the marks into an integer.

Step 2: Conditional execution

The if...else statement compares the marks with the passing threshold.

Step 3: Variable assignment

The program assigns either "Pass" or "Fail" to the result variable.

Step 4: Output

The print() statements display the student's details and result.

This small application combines input operations, assignment statements, a compound conditional statement, and output function calls.

Important Validation Note

The example assumes the user enters a valid integer for marks. If the user enters text such as "seventy", the program will raise a ValueError.

You can extend the program with exception handling and range validation to make it more robust.

Common Mistakes When Writing Python Statements

1. Missing Colon

Incorrect:

# if age >= 18
#     print("Eligible")

Correct:

age = 20

if age >= 18:
    print("Eligible")

The colon introduces the compound statement's body.

2. Incorrect Indentation

Incorrect:

# if True:
# print("Hello")

Correct:

if True:
    print("Hello")

The body must be indented.

3. Confusing Assignment and Comparison

The assignment operator = assigns a value.

The equality operator == compares values.

Example:

number = 10

if number == 10:
    print("The number is ten")

Output:

The number is ten

4. Forgetting to Update a Loop Variable

Consider a while loop that never changes its condition variable.

# count = 1
#
# while count <= 3:
#     print(count)

If executed as written without changing count, this loop continues indefinitely because count remains 1.

A corrected version is:

count = 1

while count <= 3:
    print(count)
    count += 1

Output:

1
2
3

Conclusion

Python statements are the foundation of Python programming. Simple statements perform operations such as assigning values, importing modules, and calling functions. Compound statements organize execution through conditions, loops, exception handling, and definitions.

By practicing these concepts, you will be able to write programs that accept input, process information, make decisions, and repeat operations.

Continue your Python learning journey by exploring variables, data types, operators, conditions, loops, and functions.

Recommended next step: Practice each statement type with small programs and modify the examples to observe how Python executes different instructions.

Next: Python Output Text | EDUNAVO

Frequently Asked Questions

1. What is a statement in Python?

A statement is an instruction that forms part of a Python program, such as an assignment, a function call, or an if statement.

2. What are the two main introductory categories of Python statements?

They are simple statements and compound statements.

3. What is the difference between break and continue?

break terminates the nearest enclosing loop, while continue skips the remainder of the current iteration and moves to the next one.

4. What does the pass statement do?

The pass statement performs no operation and can serve as a placeholder where a statement is required.

5. Why is indentation important in Python?

Indentation defines the body of compound statements, including conditions, loops, functions, and classes.

Share this article

0 Comments

Log in to join the discussion.

No comments yet — be the first to share your thoughts.