
In this guide
- Why Learn Python?
- Step 1: Install Python and a Code Editor
- Step 2: Write Your First Program
- Step 3: Variables and Data Types
- Step 4: Do Maths and Work With Text
- Step 5: Get Input From the User
- Step 6: Make Decisions With if Statements
- Step 7: Repeat Things With Loops
- Step 8: Store Collections: Lists, Dictionaries and More
- Step 9: Write Your Own Functions
- Step 10: Handle Errors Gracefully
- Step 11: Use Modules and Libraries
- Step 12: Build Small Projects
- How to Learn Faster
- Common Beginner Mistakes
- A Four-Week Learning Plan
- What to Learn Next
- Frequently Asked Questions
- Final Thoughts
Python is one of the most popular programming languages in the world, and for good reason. It reads almost like English, it is free, and it is used for websites, data analysis, automation, artificial intelligence, games and more. If you have ever wanted to learn to code but did not know where to start, Python is an excellent first language.
This guide takes you from zero to writing real programs. You do not need any previous experience, and you will understand not just what to type but why.
Why Learn Python?
- Beginner-friendly: the syntax is clean and readable.
- Versatile: used in web development, data science, automation, AI and cybersecurity.
- In demand: consistently one of the most requested programming skills by employers.
- Huge community: countless free tutorials, libraries and forums to help when you are stuck.
- Free: no licence cost.
Step 1: Install Python and a Code Editor
- Go to the official Python website, python.org, and download the latest stable version for your system.
- On Windows, tick “Add Python to PATH” during installation. This one checkbox prevents many beginner headaches.
- Install a code editor. Visual Studio Code is free and popular. Thonny and IDLE are simple options built for beginners.
- To test, open a terminal or command prompt and type
python --version(orpython3 --versionon Mac and Linux).
If you prefer not to install anything, try a free online editor in your browser while you learn.
Step 2: Write Your First Program
Create a file called hello.py and type:
print("Hello, world!")
Run it, and you will see the message appear. Congratulations, you are now a programmer. print() displays text on the screen.
Step 3: Variables and Data Types
A variable is a name that stores a value.
name = "Amina"
age = 25
height = 1.68
is_student = True
The main data types are:
- str (string): text, such as
"Hello" - int: whole numbers, such as
42 - float: decimals, such as
3.14 - bool:
TrueorFalse
Use print(type(age)) to check a variable’s type. Python variable names are case-sensitive, so Age and age are different.
Step 4: Do Maths and Work With Text
print(10 + 5) # 15
print(10 - 5) # 5
print(10 * 5) # 50
print(10 / 4) # 2.5
print(10 // 4) # 2 (whole-number division)
print(10 % 4) # 2 (remainder)
print(2 ** 3) # 8 (power)
Anything after # is a comment, which Python ignores. Comments help you and others understand your code.
Text can be combined and formatted:
first = "Ada"
last = "Lovelace"
full = first + " " + last
print(f"Hello, {full}!") # f-string
print(full.upper())
print(len(full))
Step 5: Get Input From the User
name = input("What is your name? ")
print("Nice to meet you, " + name)
Note that input() always returns text. To use it as a number, convert it:
age = int(input("How old are you? "))
print("Next year you will be", age + 1)
Step 6: Make Decisions With if Statements
score = 72
if score >= 80:
print("Excellent")
elif score >= 50:
print("Pass")
else:
print("Try again")
Pay close attention to the indentation (the spaces at the start of a line). Python uses indentation to know which lines belong inside the if. Four spaces is the standard.
Comparison operators include == (equal), != (not equal), <, >, <= and >=. Combine conditions with and, or and not.
Step 7: Repeat Things With Loops
A for loop repeats code for each item in a sequence.
for i in range(5):
print("Round", i)
A while loop repeats while a condition is true.
count = 3
while count > 0:
print(count)
count = count - 1
print("Go!")
Be careful: if the condition never becomes false, the loop runs forever. Press Ctrl + C in the terminal to stop it.
Step 8: Store Collections: Lists, Dictionaries and More
Lists
fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
print(fruits[0]) # apple (counting starts at 0)
print(len(fruits)) # 4
for fruit in fruits:
print(fruit)
Dictionaries
A dictionary stores pairs of keys and values.
student = {"name": "Omar", "age": 20, "course": "Maths"}
print(student["name"])
student["age"] = 21
Other useful collections are tuples (fixed lists) and sets (unique items).
Step 9: Write Your Own Functions
A function is a reusable block of code.
def greet(name):
return "Hello, " + name + "!"
print(greet("Sara"))
print(greet("Ali"))
Functions keep your code tidy and let you avoid repeating yourself. Parameters (like name) are the inputs, and return sends back a result.
Step 10: Handle Errors Gracefully
try:
number = int(input("Enter a number: "))
print(10 / number)
except ValueError:
print("That was not a number.")
except ZeroDivisionError:
print("You cannot divide by zero.")
Errors are normal. Read the error message carefully, because it tells you the type of problem and the line number.
Step 11: Use Modules and Libraries
Python comes with built-in modules, and thousands more can be installed with pip.
import random
print(random.randint(1, 10))
import datetime
print(datetime.date.today())
Popular libraries to explore later include pandas and matplotlib (data), requests (web), Flask and Django (websites), pygame (games) and scikit-learn (machine learning).
Step 12: Build Small Projects
You learn to code by building things. Start with these beginner projects:
- Number guessing game: the computer picks a number and you guess it.
- Simple calculator: ask for two numbers and an operation.
- To-do list in the terminal: add, view and remove tasks.
- Password generator: create random strong passwords.
- Quiz app: store questions in a dictionary and keep score.
- File organizer: sort files in a folder into subfolders by type.
- Expense tracker: save entries to a file and calculate totals.
Here is a tiny guessing game to get you started:
import random
secret = random.randint(1, 20)
guess = 0
while guess != secret:
guess = int(input("Guess a number from 1 to 20: "))
if guess < secret:
print("Too low")
elif guess > secret:
print("Too high")
print("You got it!")
How to Learn Faster
- Code every day, even for 20 to 30 minutes. Consistency beats marathon sessions.
- Type the code yourself instead of copying and pasting.
- Change examples and see what breaks. Experimenting teaches more than reading.
- Read error messages and search them online. Every programmer does this daily.
- Break problems down into small steps before coding.
- Use AI tools as a tutor, asking them to explain code or errors, but write the solutions yourself first.
- Join a community such as a forum or study group, so you can ask questions.
Common Beginner Mistakes
- Forgetting the colon
:at the end ofif,for,whileanddeflines - Mixing tabs and spaces in indentation
- Using
=(assign) when you meant==(compare) - Forgetting that list positions start at 0
- Not converting
input()to a number - Watching endless tutorials without building anything (“tutorial hell”)
A Four-Week Learning Plan
- Week 1: install Python, variables, data types, input and output, maths.
- Week 2: if statements and loops. Build a guessing game.
- Week 3: lists, dictionaries and functions. Build a to-do list.
- Week 4: modules, file handling and error handling. Build a small project of your own.
What to Learn Next
- Data analysis: pandas, NumPy and matplotlib.
- Web development: Flask or Django, plus HTML and CSS.
- Automation: scripts that rename files, send emails or scrape websites responsibly.
- Machine learning: start after you are comfortable with data basics.
- Git and GitHub: to save your code and show your portfolio to employers.
Frequently Asked Questions
How long does it take to learn Python?
You can learn the basics in four to eight weeks of regular practice. Becoming job-ready takes longer, usually several months of projects and study.
Do I need to be good at maths?
Not for the basics. Everyday programming needs only simple arithmetic and logic. Some fields, like machine learning, use more maths later.
Is Python free?
Yes, Python and most of its libraries are free and open source.
Can I get a job with Python?
Many roles use it, including data analyst, backend developer, automation engineer and QA tester. A portfolio of projects helps greatly.
Python 2 or Python 3?
Always use Python 3. Python 2 is no longer supported.
Final Thoughts
Learning Python is like learning any skill: it feels awkward at first and becomes natural with practice. Install it today, write your first print statement, and build one small project this week. Every expert programmer started exactly where you are now.




















































