Python Programming Tutorial for Beginners
1. Program Development Phases and Steps
Program development is the process of planning, writing, testing, and maintaining programs in an organized way.
It helps turn ideas into reliable working software. Following these steps reduces errors, saves time, and improves
program quality. These phases are used by both beginners and professionals.
Phases of Program Development:
1️⃣ Problem Definition
Understand and clearly describe what the program must do. Example: "Write a program to calculate the average of
three numbers."
2️⃣ Planning and Design
Decide how to solve the problem, often using algorithms, flowcharts, and pseudocode. Example: Draw a flowchart
showing input three numbers → calculate sum → divide by 3 → show average.
3️⃣ Coding (Implementation)
Translate your plan into code in Python. Example:
a = 10
b = 20
c = 30
average = (a + b + c) / 3
print("Average:", average)
4️⃣ Testing and Debugging
Run the program with test data and fix errors. Example: Try numbers like (5,10,15) and check average.
5️⃣ Documentation
Add comments and user guides to explain how the program works.
6️⃣ Maintenance
Update the program when needed or add new features. Example: allow user input instead of fixed numbers.
Student Activity: Choose a simple problem (like sum of two numbers). Write its problem
definition, algorithm/flowchart, code, and test it.
2. Introduction to Python
Python is a high-level, interpreted programming language created by Guido van Rossum in 1991. Its clean,
readable syntax makes it perfect for beginners. Python supports different programming styles like procedural,
object-oriented, and functional programming. It’s widely used in web development, data science, AI, and more.
Uses: Web development, data science, machine learning, scripting, and games.
Limitations: Slower than compiled languages, higher memory use, limited mobile support.
3. 🌟 Features of Python
✅ Easy to Learn and Read :
Python have simple words and syntax similar to English, that makes coding easier.
✅ Free and Open Source:
Python is an Open-Source language which means that anyone can use and modify Python freely.
✅ High-Level Language
Python is considered a high-level language because its commands and syntax look like normal English.
It hides complex details like memory management from the programmer.
This makes writing and understanding code much easier, especially for beginners.
✅ Portable
Python programs can run on different operating systems like Windows, macOS, and Linux with no or
very few changes.
This means you can share your code with others regardless of what computer they use.
It helps developers build software that works everywhere.
✅ Interpreted Language
Python code is executed line by line by an interpreter rather than being compiled all at once.
This makes testing and debugging easier, because you can run parts of the code quickly and fix problems
on the spot.
It’s very useful when experimenting or writing scripts.
✅ Large Standard Library
Python comes with many built-in modules and functions to do tasks like file reading, math, working with
dates, and internet data.
Using these libraries saves a lot of coding time and effort.
It also helps beginners focus on logic instead of building everything from scratch.
✅ Supports Multiple Programming Paradigms
Python supports procedural programming (step by step), object-oriented programming (using classes and
objects), and functional programming (using functions).
This flexibility lets programmers choose the best way to solve a problem.
It’s useful for both small scripts and large, complex projects.
✅ Extensible and Embeddable
Python can be extended by adding modules written in other languages like C or C++.
This helps when you need to speed up parts of your program or use special hardware.
You can also embed Python inside other applications to add scripting features.
✅ Dynamically Typed
In Python, you don’t need to declare variable types like int, float, or string before using them.
Python figures out the type at runtime based on the value assigned.
This makes code shorter and easier to write, but you still have to be careful with variable values.
Student Activity: Choose 3 features and write why you like them.
📌 Detailed Uses of Python in Different Fields
✅ Web Development
Python is widely used to build dynamic websites and web applications.
Frameworks like Django and Flask help developers create secure, scalable websites quickly.
Its simple syntax makes connecting to databases and adding features easier.
✅ Data Science & Machine Learning
Python is a favorite language for analyzing data and building AI models.
Libraries like pandas, NumPy, and scikit-learn make data cleaning, visualization, and prediction simpler.
It’s used in businesses to find trends, make forecasts, and support decisions.
✅ Automation & Scripting
Python is great for writing small scripts that save time and reduce manual work.
Examples include renaming files, sending emails, or downloading data automatically.
Even beginners can automate tasks in just a few lines of code.
✅ Game Development
Python can be used to create simple games and prototypes quickly.
Libraries like Pygame provide tools to manage graphics, sounds, and game loops.
While large games may need faster languages, Python is excellent for learning and testing ideas.
✅ Internet of Things (IoT)
Python runs on small devices like Raspberry Pi to control lights, sensors, and cameras.
It helps create smart home projects and prototypes without complex code.
Its readability makes it popular for students and hobbyists.
✅ Scientific Computing & Research
Scientists and researchers use Python for data analysis, simulations, and mathematical models.
Libraries like SciPy and SymPy handle complex calculations easily.
It speeds up research and helps turn theories into practical solutions.
✅ Desktop Applications
Python can create desktop software with buttons, menus, and forms.
Tools like Tkinter and PyQt let developers design user-friendly programs.
Examples include calculators, notepads, and small business apps.
Student Activity: Install Python and write the version you installed.
4. What is IDE
An IDE (Integrated Development Environment) is a complete software package that helps programmers write,
test, and debug code easily from a single window. The basic parts of an IDE usually include:
• Code Editor: The main area to write and edit source code, often with features like syntax highlighting and
auto-complete.
• Compiler/Interpreter: Converts your code into machine language so it can be executed.
• Debugger: Helps find and fix errors by letting you run code step by step and see what’s happening inside.
• Terminal/Console: Allows running commands and viewing program output directly within the IDE.
• Project Explorer: Organizes files and folders for easy navigation and management.
One popular IDE for beginners in Python is Thonny IDE. Thonny is specially designed to be simple and user-
friendly, making it ideal for those who are just starting to learn programming. It has a clean interface, built-in
Python shell, and an easy-to-use debugger that shows variables and steps clearly. Thonny also helps beginners
understand how Python works internally by showing how code is executed line by line. This makes learning to
code less intimidating and much clearer.
Thonny IDE
5. Installing Thonny IDE
1. Visit [Link]
Go to the official website [Link]
Here you’ll find download options for Windows, macOS, and Linux.
2. Download installer
Choose the installer that matches your operating system.
Click to download; the file will be saved to your computer.
3. Run installer and follow steps
Double-click the downloaded file to start the installation.
Follow the on-screen instructions (usually clicking “Next” and “Finish”).
4. Open Thonny and start coding
Once installed, open Thonny from your desktop or start menu.
You’re ready to write, run, and debug Python code in a beginner-friendly environment!
Activity: Install Thonny and run print ("Hello from Thonny!")
6. Writing Your First Python Program
Programs are instructions to solve a task. Python makes it easy to start. Example:
Print ("Hello, World!")
Writing Your First Python Program - Example Programs
print("Hello, World!")
print("Welcome to Python!")
print("My first Python script.")
Activity: Change text from “Hello World “ to print your own name.
7. Variables & Data Types
Variables store data in memory. Data types define what kind of data is stored. Python decides type automatically.
Example: name = "Sara"; age = 18; height = 5.4; is_student = True
Data types include: int, float, str, bool, list, tuple, dict, set.
Activity: Create variables for your name, age, height, is_student, hobbies list.
8. Operators
Operators are symbols that help to perform calculations and comparisons.
✅ Types of Operators in Python
🔹 1. Arithmetic Operators
Used to perform mathematical calculations. Used to compare two values and return True or
False.
• + Addition (e.g., 5 + 2 = 7)
• == Equal to
• - Subtraction (e.g., 5 - 2 = 3)
• != Not equal to
• * Multiplication (e.g., 5 * 2 = 10)
• > Greater than
• / Division (e.g., 5 / 2 = 2.5)
• < Less than
• % Modulus (remainder, e.g., 5 % 2 = 1)
• >= Greater than or equal to
• ** Exponentiation (power, e.g., 5 ** 2 = 25)
• <= Less than or equal to
• // Floor division (e.g., 5 // 2 = 2)
🔹 4. Logical Operators
🔹 2. Assignment Operators
Used to combine conditional statements.
Used to assign values to variables.
• and Returns True if both statements are true
• = Assign (e.g., x = 5)
• or Returns True if at least one statement is
• += Add and assign (e.g., x += 2 → x = x + 2) true
• -= Subtract and assign • not Reverses the result (True becomes False)
• *= Multiply and assign
🔹 5. Bitwise Operators
• /= Divide and assign
Used to perform bit-level operations.
• %= Modulus and assign
• & AND
• **= Exponent and assign
• | OR
• //= Floor division and assign
• ^ XOR
🔹 3. Comparison Operators • ~ NOT
• << Left shift • in Returns True if value is found in sequence
• >> Right shift • not in Returns True if value is not found in
sequence
🔹 6. Membership Operators
Used to test if a sequence contains a value.
🔹 7. Identity Operators
Used to compare objects (not just values).
• is Returns True if two variables point to the same object
• is not Returns True if two variables point to different objects. Of course! Here’s a point-wise explanation
of data types used in Python with short definitions and subtopics, in the same clear format:
✅ Data Types in Python
Python has several built-in data types, grouped into • tuple : Immutable ordered list (e.g.,
categories: coordinates = (10, 20))
🔹 1. Numeric Types 🔹 3. Mapping Type
• Used to store numbers. • Stores key-value pairs.
• int : Integer numbers (e.g., x = 5) • dict : Dictionary (e.g., student =
• float : Floating-point (decimal) {"name": "Ali", "age": 20})
numbers (e.g., y = 3.14)
• complex : Complex numbers with 🔹 4. Set Types
real and imaginary parts (e.g., z = 2
• Unordered collection of unique
+ 3j)
items.
🔹 2. Sequence Types • set : Mutable set (e.g., colors =
{"red", "green"})
• Ordered collections of items. • frozenset : Immutable set
• str : String of text (e.g., name =
"Ali") 🔹 5. Boolean Type
• list : Mutable ordered list (e.g., fruits
• Used to store True or False.
= ["apple", "banana"])
• bool : (e.g., is_active = True)
🔹 6. Binary Types
• Used to handle binary data.
• bytes : Immutable sequence of bytes (e.g., b'abc')
• bytearray : Mutable sequence of bytes
• memoryview : Memory view object for handling large data
Variables & Data Types - Example Programs
Example 1.
name = "Ali" Example 2.
print("Name:", name) a = 15
age = 25 b=4
print("Age:", age) print("Addition:", a+b)
height = 5.9 print("a > b:", a > b)
is_student = True c=a*b
print("Height:", height, "Student:", is_student) print("Multiplication:", c)
Example 2:
Program: Output:
Activity: Write a program using at least 3 types of operators.
9. Conditional Statements
Conditional statements let programs choose actions based on conditions. Types: if, if-else, if-elif-else,
nested if.
Example:
if score>=50: print("Pass") else: print("Fail")
Example 2
num = 10 score = 85
if num > 0: if score >= 90:
print("Positive number") print("Grade A")
marks = 45 elif score >= 75:
if marks >= 50: print("Grade B")
print("Pass") else:
else: print("Grade C")
print("Fail")
Activity: Write code to check if a number is positive, negative, or zero.
10. Loops
Loops repeat code. for loops run for each item; while loops run while a condition is true.
Loops - Example 3
Loops - Example 1-2 for i in range(1, 4):
1. for i in range(1,6): print("Loop iteration:", i)
print(i); count = 1
count=1; while count <= 3:
2. while count<=5: print("While loop count:", count)
print(count); count += 1
for char in "ABC":
count+=1
print(char)
Activity: Use a for loop to print numbers 10 to 1; use while loop to print name 3 times.
11. Functions
Functions are reusable blocks of code. Built-in (print, len) and user-defined (def greet():).
Example 2
Example: def say_hello():
def greet(): print("Hello!")
say_hello()
print("Hello"); def add_numbers(a, b):
print("Sum:", a+b)
greet() add_numbers(5, 7)
def greet(name):
print("Hi,", name)
greet("Sara")
Activity: Write a user-defined function that prints your name and call it.
12. Lists
Lists are ordered collections written in []. They can be homogeneous, heterogeneous, or nested.
numbers = [10, 20, 30]
Types of Lists numbers. append(40)
1. numbers=[1,2,3]; print(numbers)
2. mixed=["Sara",18,True]; fruits = ["apple", "banana", "cherry"]
fruits[1] = "orange"
3. nested=[1,2,[3,4]]
print(fruits)
Example 2
colors = ["red", "green", "blue"]
print(colors)