Back to Modules

Python Tutorial

Master Python programming with our comprehensive tutorial. Learn through examples and hands-on practice with Python's elegant syntax.

Full Video Tutorial

Introduction to Python

Python is a high-level, interpreted programming language known for its simplicity and readability.

Examples:

# Simple Hello World program
print("Hello World!")

A simple Hello World program in Python

Python Basics

Learn fundamental Python concepts including variables, data types, and basic operations.

Examples:

# Data types and variables
number = 42
pi = 3.14159
grade = 'A'
is_valid = True
name = "John"

# Dynamic typing
x = 100      # x is an integer
x = "Python" # now x is a string

Common data types and variable declarations in Python

# Lists in Python
numbers = [1, 2, 3, 4, 5]
names = []

# List operations
numbers.append(6)
numbers.extend([7, 8])
first_item = numbers[0]
last_item = numbers[-1]

Lists and basic list operations

Python Functions

Functions in Python are defined using the def keyword and are essential for code organization.

Examples:

def greet(name, greeting="Hello"):
    """
    A simple greeting function
    with optional parameter
    """
    return f"{greeting}, {name}!"

# Function calls
print(greet("Alice"))         # Hello, Alice!
print(greet("Bob", "Hi"))     # Hi, Bob!

# Lambda function
square = lambda x: x * x
print(square(5))              # 25

Functions and lambda expressions in Python

Control Flow and Loops

Learn how to control program flow using conditional statements and loops in Python.

Examples:

# If-elif-else statement
score = 85
if score >= 90:
    grade = 'A'
elif score >= 80:
    grade = 'B'
else:
    grade = 'C'

# For loop with range
for i in range(5):
    print(i)

# While loop
count = 0
while count < 3:
    print(f"Count: {count}")
    count += 1

# List comprehension
squares = [x**2 for x in range(5)]

Examples of control flow statements and loops in Python