INTRODUCTION TO PYTHON
Programming Basics for Beginners
Original educational material • Free to use, share, and upload
1. What is Python?
Python is a high-level, general-purpose programming language known for its clear and readable syntax. It is
widely used in web development, data analysis, artificial intelligence, automation, scientific computing, and
education. Python emphasizes code readability and allows programmers to express concepts in fewer lines
than many other languages.
2. Installing and Running Python
You can download Python from the official website ([Link]). After installation, you can run Python code
in three common ways:
• Interactive shell (type python or python3 in a terminal)
• Script files with a .py extension
• Online interpreters or Jupyter notebooks
3. Basic Syntax and Variables
Python uses indentation (usually 4 spaces) to define blocks of code instead of curly braces. Variables are
created by assignment and do not need explicit type declarations.
Examples:
• name = "Alex" # string
• age = 21 # integer
• height = 1.75 # float
• is_student = True # boolean
4. Core Data Types
4.1 Numbers
Integers (int) and floating-point numbers (float) support the usual arithmetic operations: +, -, *, /, // (floor
division), % (modulo), and ** (exponent).
4.2 Strings
Strings are sequences of characters enclosed in single or double quotes. Common operations include
concatenation (+), repetition (*), slicing, and methods such as .upper(), .lower(), .strip(), and .split().
4.3 Lists
Lists are ordered, mutable collections written with square brackets. Example: scores = [88, 92, 75, 90]. You
can append, insert, remove, and slice lists.
4.4 Dictionaries
Dictionaries store key-value pairs. Example: person = {"name": "Alex", "age": 21}. Access values with
person["name"].
Original educational material • Free to share and upload Page 1
4.5 Tuples and Sets
Tuples are immutable sequences. Sets are unordered collections of unique elements, useful for
membership tests and removing duplicates.
5. Control Flow
5.1 Conditionals
Use if, elif, and else to make decisions. Conditions evaluate to True or False.
5.2 Loops
for loops iterate over sequences. while loops repeat as long as a condition remains true. Use break to exit
early and continue to skip to the next iteration.
6. Functions
Functions are defined with the def keyword. They can accept parameters and return values. Example:
def greet(name):
return f"Hello, {name}!"
Functions help organize code, avoid repetition, and make programs easier to test and maintain.
7. Simple Practice Exercises
1. Write a program that asks for a user’s name and age, then prints a greeting including both.
2. Create a list of five numbers and print their sum and average.
3. Write a function that takes a string and returns it reversed.
4. Use a loop to print the first 10 multiples of 3.
5. Create a dictionary of three fruits and their prices, then print each fruit with its price.
8. Next Steps
After mastering these basics, explore modules (import math, random, datetime), file handling, list
comprehensions, and error handling with try/except. Consistent practice writing small programs is the fastest
way to improve.
— End of Guide — Original content created for free distribution —
Original educational material • Free to share and upload Page 2