Back

Let's learn python

Learn python with me

Python — The Language

Alright, let’s talk about Python.

If you’re reading this, you’re probably someone who either just got into programming, or you’ve heard everyone and their uncle say “learn Python first” and you wanna know why. Either way, you’re in the right place.

This is going to be long. Grab water. Let’s go.


Wait — What Even Is Programming?

Before we touch Python, let’s get one thing clear in your head.

A computer is just a machine. It doesn’t think. It only does exactly what you tell it to do — nothing more, nothing less. Programming is the act of giving the computer those instructions.

The problem? Computers don’t speak Bengali. They don’t speak English either. Deep down, they only understand 0s and 1s — binary. Raw electrical signals. On or off.

So how does your Instagram app talk to the computer? That’s where programming languages come in.


Low-Level vs High-Level Languages

Think of it like this:

Imagine you want to tell someone to make tea. If you’re talking to a machine at the lowest level, you’d have to say: “Move hand forward 23.5 degrees. Apply 4.2 newton-force on handle. Lift 17 centimeters.”

That’s low-level language — close to the machine, extremely precise, but absolutely painful to write.

High-level language is more like: “Make me tea.” The machine figures out the rest.

Here’s the rough breakdown:

LevelLanguageCloseness to MachineHuman-Friendliness
LowestBinary (Machine Code)100%0%
LowAssemblyHighVery Low
MidC, C++, RustMediumMedium
HighPython, JavaScriptLowVery High

Python sits at the top of that list. It reads almost like plain English. That’s literally why beginners love it, and why experienced engineers still use it for serious work.


The Translators: Assembler, Compiler, and Interpreter

So if you write Python code (high-level), how does the computer actually understand it? Something has to translate your code down to machine language.

That “something” is called a translator program. There are three types:

Assembler

An assembler converts assembly language (low-level, human-readable symbols like MOV, ADD) into machine code (binary). It’s a 1-to-1 translation — one assembly instruction becomes one machine instruction.

Nobody really writes assembly day-to-day anymore unless they’re doing embedded systems or OS-level hacking. But it exists, and it’s fast as hell.

Compiler

A compiler takes your entire source code (like a C or C++ file), reads it all at once, and converts it to machine code before you run it. The output is an executable file (like a .exe on Windows).

  • You write the code
  • Compiler translates the whole thing
  • You run the compiled output

Examples: C, C++, Rust, Go

Pros: Very fast at runtime because translation already happened
Cons: If there’s an error anywhere, nothing runs until you fix it

Interpreter

An interpreter reads and executes your code line by line, in real time. There’s no pre-compilation step. You run the file, it starts executing from line 1, and if something breaks on line 47, it runs fine up to line 46 and then crashes.

  • You write the code
  • Interpreter reads and runs it line by line

Examples: Python, JavaScript (kinda), Ruby, PHP

Pros: Flexible, easy to debug, great for scripting
Cons: A bit slower than compiled languages at heavy computation

Python is an interpreted language. When you run python hello.py, the Python interpreter reads each line and executes it on the spot. That’s it.


Installing Python

Windows

  1. Go to python.org/downloads
  2. Download the latest version (3.x.x)
  3. Run the installer
  4. Important: On the first screen, check the box that says Add Python to PATH. Don’t skip this.
  5. Click “Install Now”

Verify it worked by opening Command Prompt and typing:

python --version

You should see something like Python 3.12.3.


macOS

macOS often has an old Python 2 installed by default. You don’t want that.

Option 1 — Official installer:

  1. Go to python.org/downloads
  2. Download the macOS installer
  3. Run it, follow the steps

Option 2 — Homebrew (recommended if you already use brew):

brew install python

Verify:

python3 --version

On Mac, you’ll usually type python3 instead of python.


Linux

Most Linux distros come with Python 3 pre-installed. Check first:

python3 --version

If it’s not there, install it via your package manager:

Ubuntu / Debian / Kali:

sudo apt install python3

Fedora:

sudo dnf install python3

Arch:

sudo pacman -S python

Termux (Android)

If you’re on Android and using Termux (which is honestly underrated), this is all you need:

pkg update && pkg upgrade
pkg install python

Done. That’s it. You can now run Python straight from your phone. Wild, right?


Your First Python Program

Open any text editor. Create a file called hello.py. Type this:

print("Hello, World!")

Now run it:

python hello.py

Output:

Hello, World!

Congrats. You just wrote and ran your first Python program. Simple as that.

print() is a built-in Python function that displays something on the screen. Whatever you put inside the parentheses (wrapped in quotes if it’s text) gets printed out.


Variables

A variable is just a box with a name where you store data.

name = "Shoudo"
age = 18
city = "Dhaka"

print(name)   # Shoudo
print(age)    # 18
print(city)   # Dhaka

You don’t need to declare the type. Python figures it out on its own. Just name = value and you’re done.

Variable naming rules:

  • Can contain letters, numbers, underscores
  • Cannot start with a number
  • Case-sensitive (name and Name are different)
  • No spaces (use _ instead: my_name)

Data Types

Python has several built-in data types. These are the ones you’ll use constantly:

# String — text
name = "Shoudo"

# Integer — whole number
age = 18

# Float — decimal number
gpa = 3.75

# Boolean — True or False
is_student = True
is_rich = False

# NoneType — nothing/null
nothing = None

You can check the type of anything using type():

print(type(name))      # <class 'str'>
print(type(age))       # <class 'int'>
print(type(gpa))       # <class 'float'>
print(type(is_student)) # <class 'bool'>

Math in Python

Python handles math exactly the way you’d expect:

a = 10
b = 3

print(a + b)   # 13 — addition
print(a - b)   # 7  — subtraction
print(a * b)   # 30 — multiplication
print(a / b)   # 3.333... — division (always returns float)
print(a // b)  # 3  — floor division (no decimal)
print(a % b)   # 1  — modulo (remainder)
print(a ** b)  # 1000 — power (10 to the 3rd = 1000)

Order of operations works like regular math — parentheses first, then powers, then multiply/divide, then add/subtract (BODMAS / PEMDAS).

result = (2 + 3) * 4 ** 2 / 8
print(result)  # 10.0

Conditional Logic — if / elif / else

This is where code gets interesting. You can make decisions.

age = 18

if age >= 18:
    print("You can vote.")
elif age >= 13:
    print("You're a teenager.")
else:
    print("You're a kid.")

The structure:

  • if — check a condition
  • elif — else if (another condition, checked only if the previous one was False)
  • else — runs if nothing above was True

Comparison operators:

x == y   # equal to
x != y   # not equal to
x > y    # greater than
x < y    # less than
x >= y   # greater than or equal to
x <= y   # less than or equal to

Logical operators:

# and — both must be True
if age >= 18 and has_id == True:
    print("Access granted")

# or — at least one must be True
if is_admin or is_moderator:
    print("You have access")

# not — flips True to False and vice versa
if not is_banned:
    print("Welcome!")

Loops

Loops let you repeat code. Two main types: for and while.

for Loop

A for loop runs over a sequence — a list, a range, a string, whatever.

# Loop over a range of numbers
for i in range(5):
    print(i)  # prints 0, 1, 2, 3, 4

# range(start, stop, step)
for i in range(1, 10, 2):
    print(i)  # 1, 3, 5, 7, 9

# Loop over a list
fruits = ["mango", "banana", "lychee"]
for fruit in fruits:
    print(fruit)

# Loop over a string
for letter in "Python":
    print(letter)

while Loop

A while loop keeps running as long as a condition is True.

count = 0

while count < 5:
    print(count)
    count += 1   # count = count + 1

Be careful with while — if the condition never becomes False, it runs forever. That’s called an infinite loop and it’ll freeze your program.

break and continue

These two keywords give you more control inside loops.

break — exits the loop completely:

for i in range(10):
    if i == 5:
        break        # stops the loop when i hits 5
    print(i)         # prints 0, 1, 2, 3, 4

continue — skips the current iteration and moves to the next:

for i in range(10):
    if i % 2 == 0:
        continue     # skip even numbers
    print(i)         # prints 1, 3, 5, 7, 9

Functions

Functions are reusable blocks of code. Instead of writing the same logic 10 times, you write it once as a function and call it whenever you need it.

def greet(name):
    print(f"Yo, {name}! What's up?")

greet("Shoudo")   # Yo, Shoudo! What's up?
greet("Ruhan")    # Yo, Ruhan! What's up?

Functions that return values:

def add(a, b):
    return a + b

result = add(5, 3)
print(result)   # 8

Default parameter values:

def power(base, exp=2):
    return base ** exp

print(power(4))      # 16 (uses default exp=2)
print(power(4, 3))   # 64

f-strings (the clean way to format strings):

name = "Shoudo"
age = 18
print(f"My name is {name} and I'm {age} years old.")

Strings — Going Deeper

Strings are text. And Python gives you a ton of tools to work with them.

s = "Hello, World!"

print(len(s))           # 13 — length
print(s.upper())        # HELLO, WORLD!
print(s.lower())        # hello, world!
print(s.replace("World", "Python"))  # Hello, Python!
print(s.split(", "))    # ['Hello', 'World!']
print(s.strip())        # removes whitespace from both ends
print(s[0])             # H — indexing (starts at 0)
print(s[7:12])          # World — slicing
print(s[-1])            # ! — last character

String methods are super useful:

text = "  shoudo  "
print(text.strip())    # "shoudo"
print(text.title())    # "  Shoudo  "

sentence = "python is cool"
print(sentence.startswith("python"))  # True
print(sentence.endswith("cool"))      # True
print("python" in sentence)           # True

Lists

A list is an ordered collection of items. You can store anything in a list — numbers, strings, even other lists.

devices = ["phone", "laptop", "earbuds"]

# Indexing
print(devices[0])    # phone
print(devices[-1])   # earbuds (last item)

# Slicing
print(devices[0:2])  # ['phone', 'laptop']

# Modify
devices[1] = "PC"
print(devices)       # ['phone', 'PC', 'earbuds']

# Add items
devices.append("tablet")       # adds to the end
devices.insert(1, "keyboard")  # inserts at position 1

# Remove items
devices.remove("earbuds")   # removes by value
devices.pop()               # removes last item
devices.pop(0)              # removes item at index 0

# Other useful methods
print(len(devices))          # number of items
print(devices.count("phone")) # how many times "phone" appears
devices.sort()               # sort alphabetically / numerically
devices.reverse()            # reverse the list

Looping over a list:

numbers = [1, 2, 3, 4, 5]
for num in numbers:
    print(num * 2)

# With index using enumerate()
fruits = ["mango", "banana", "lychee"]
for index, fruit in enumerate(fruits):
    print(f"{index}: {fruit}")

List Comprehensions

This is one of those Python things that looks weird at first but once you get it, you’ll use it everywhere.

A list comprehension is a compact way to create a new list based on some logic.

Normal way:

squares = []
for i in range(1, 6):
    squares.append(i ** 2)
print(squares)  # [1, 4, 9, 16, 25]

Comprehension way:

squares = [i ** 2 for i in range(1, 6)]
print(squares)  # [1, 4, 9, 16, 25]

Same result, one line. Cleaner, faster.

With a condition:

# Only even numbers squared
evens_squared = [i ** 2 for i in range(1, 11) if i % 2 == 0]
print(evens_squared)  # [4, 16, 36, 64, 100]

String manipulation:

words = ["hello", "world", "python"]
upper_words = [word.upper() for word in words]
print(upper_words)  # ['HELLO', 'WORLD', 'PYTHON']

Sets

A set is an unordered collection of unique items. No duplicates. No guaranteed order.

my_set = {1, 2, 3, 4, 4, 5, 5}
print(my_set)   # {1, 2, 3, 4, 5} — duplicates removed

# Add items
my_set.add(6)

# Remove items
my_set.remove(3)    # raises error if not found
my_set.discard(10)  # safe remove — no error if not found

# Check membership
print(3 in my_set)  # False (we removed it)
print(6 in my_set)  # True

Set operations (math-style):

a = {1, 2, 3, 4}
b = {3, 4, 5, 6}

print(a | b)   # union — {1, 2, 3, 4, 5, 6}
print(a & b)   # intersection — {3, 4}
print(a - b)   # difference — {1, 2}
print(a ^ b)   # symmetric difference — {1, 2, 5, 6}

Sets are great when you want to remove duplicates from a list or do quick membership checks.


Dictionaries

A dictionary stores data as key-value pairs. Think of it like a real dictionary — you look up a word (key) and get its definition (value).

person = {
    "name": "Shoudo",
    "age": 18,
    "city": "Dhaka",
    "skills": ["Python", "Flutter", "Rust"]
}

# Accessing values
print(person["name"])    # Shoudo
print(person["skills"])  # ['Python', 'Flutter', 'Rust']

# Safe access with .get() (no error if key missing)
print(person.get("phone", "Not found"))  # Not found

# Add / update
person["job"] = "Developer"
person["age"] = 19

# Delete
del person["city"]

# Useful methods
print(person.keys())    # all keys
print(person.values())  # all values
print(person.items())   # all key-value pairs

Looping through a dictionary:

for key, value in person.items():
    print(f"{key}: {value}")

Nested dictionaries:

users = {
    "shoudo": {"age": 18, "city": "Dhaka"},
    "ruhan": {"age": 19, "city": "Dhaka"}
}

print(users["shoudo"]["city"])   # Dhaka

Random Numbers

Python’s random module is super handy for generating random values.

import random

# Random float between 0 and 1
print(random.random())

# Random integer between two values (inclusive)
print(random.randint(1, 100))

# Random float in a range
print(random.uniform(1.5, 9.5))

# Pick a random item from a list
fruits = ["mango", "banana", "lychee", "jackfruit"]
print(random.choice(fruits))

# Pick multiple random items (no repetition)
print(random.sample(fruits, 2))

# Shuffle a list in place
random.shuffle(fruits)
print(fruits)

Quick example — a dice roll simulator:

import random

def roll_dice():
    return random.randint(1, 6)

print(f"You rolled: {roll_dice()}")

Where to Go From Here

You’ve covered a lot. Seriously. Variables, data types, math, conditionals, loops, functions, strings, lists, list comprehensions, sets, dictionaries, and random numbers — that’s a real foundation.

From here, a few directions you can go:

  • Files — reading and writing files with open()
  • Error handlingtry / except blocks
  • Modules and packages — using import to bring in more tools
  • Object-Oriented Programming (OOP) — classes and objects
  • Librariesrequests for APIs, pandas for data, flask for web, pygame for games

Python is one of those languages that scales with you. You can use it to automate boring tasks, build web backends, do data science, write scripts for your Linux setup, train ML models — the list is genuinely endless.

Start small. Build something you actually care about. That’s the fastest way to learn.


Practice Along

All the code examples and exercises from this guide are in my GitHub repo. Clone it, mess around, break things, fix them.

github.com/asikrshoudo/python—practice-

I’ll keep adding more as I go — so star it if you want to follow along.


Thanks for reading my blog