Python / Basic

Learning the basics of Python is the first step to becoming confident in programming. Let’s go through each concept with simple explanations and examples.

1. Introduction to Python & Installation

Python is easy to install and runs on all major operating systems.
After installation, you can start writing code directly in the terminal or use an editor like VS Code or PyCharm.

print("Hello, Python!")
Python

2. Variables & Data Types

Variables are like containers that store information. Python automatically detects the type of data.

name = "Alice"      # string
age = 25            # integer
height = 1.68       # float
is_student = True   # boolean

print(name, age, height, is_student)
Python

3. Basic Operators

Operators allow you to perform calculations and operations.

a = 10
b = 3

print(a + b)   # addition → 13
print(a - b)   # subtraction → 7
print(a * b)   # multiplication → 30
print(a / b)   # division → 3.33
print(a % b)   # modulus (remainder) → 1
Python

4. Strings and String Methods in Python

Strings are text in Python. They come with many handy methods.

text = "Python is fun!"

print(text.upper())   # "PYTHON IS FUN!"
print(text.lower())   # "python is fun!"
print(text.replace("fun", "powerful"))  # "Python is powerful!"
print(len(text))      # length of string
Python

5. Lists, Tuples, and Dictionaries in Python

These are ways to store multiple values.

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

# Tuple (unchangeable)
colors = ("red", "green", "blue")
print(colors[0])

# Dictionary (key-value pairs)
person = {"name": "Alice", "age": 25}
print(person["name"])
Python

6. Conditional Statements (if, else, elif)

Conditions let your program make decisions.

age = 18

if age < 18:
    print("You are underage.")
elif age == 18:
    print("You are exactly 18!")
else:
    print("You are an adult.")
Python

7. Loops (for, while)

Loops repeat tasks without writing code multiple times.

# for loop
for i in range(5):
    print("Number:", i)

# while loop
count = 0
while count < 3:
    print("Count:", count)
    count += 1
Python

8. Functions & Parameters

Functions organize code into reusable blocks.

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

print(greet("Alice"))
print(greet("Bob"))
Python

👉 This section covers the fundamental building blocks of Python. By practising these topics, students will grasp the logic of the language and be able to start working on small real-world projects.

Leave a Reply

Your email address will not be published. Required fields are marked *