Python Programming


Getting Started

Python is a beginner-friendly language. Print your first program:

print("Hello, World!")

Variables and Data Types

Variables store data. No need to declare type.

name = "Alice"    # string
age = 20          # integer
height = 5.5      # float
is_student = True # boolean

If-Else Statements

Make decisions in code.

if age >= 18:
    print("Adult")
else:
    print("Minor")

Loops

Repeat code. For and While loops.

for i in range(5):
    print(i)

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

Lists and Tuples

Lists are mutable collections.

fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
print(fruits[0])  # apple

Dictionaries

Key-value pairs.

student = {"name": "Bob", "age": 22}
print(student["name"])

Functions

Reusable code blocks.

def greet(name):
    return f"Hello, {name}!"

print(greet("Alice"))
Table of Contents