Introduction
Python is a high-level, interpreted programming language known for readable syntax and broad use across web development, automation, data science, and AI. Unlike compiled languages, Python code runs line-by-line through an interpreter, which makes it easier to test and debug quickly.
Python's design philosophy favors clarity — code is meant to read almost like plain English, which is part of why it's a common first language for beginners and a serious tool for professionals.
What You Should Already Know
Before starting, you should be comfortable with basic computer literacy — installing software, using a text editor, and navigating a file system. No prior programming experience is required, but understanding basic math operations (addition, comparison) will help.
- Basic keyboard and file navigation skills
- A text editor or IDE installed (e.g., VS Code)
- Python installed and runnable from a terminal
Hello World
The traditional first program in any language prints a simple message to the screen.
In Python, this takes one line, thanks to the built-in print() function.
print("Hello, world!")
Running this file through the Python interpreter outputs Hello, World! directly to the terminal.
Variables
A variable is a name that stores a value in memory, which you can reference and reuse. Python does not require you to declare a variable's type — it's inferred automatically from the value assigned.
name = "Ray"age = 20is_learning = True
Data Types
Python has several built-in data types that determine what kind of value a variable holds and what operations can be performed on it.
int— whole numbers (e.g., 10)float— decimal numbers (e.g., 3.14)str— text (e.g., "hello")bool—TrueorFalselist— an ordered, changeable collection
x = 10# inty = 3.14# floatname = "Ray"# stris_ok = True# bool
Comparison Operators
Comparison operators compare two values and return a boolean (True or False).
They're used constantly in control flow to test conditions.
a = 10b = 5print(a > b)# Trueprint(a == b)# Falseprint(a != b)# True
==equal to!=not equal to-
><>=<=greater/less than (or equal)
Comments
Comments are lines in code that Python ignores when running the program. They exist purely to explain code to humans reading it — either yourself later, or others working on the same file.
# This is a single-line commentprint("This runs")# This explains the line
Control Flow
Control flow refers to the order in which a program's statements execute.
Python uses if, elif, and else to make decisions based on conditions.
if x > 10:print("Big")elif x == 10:print("Equal")else:print("Small")
Loops
Loops let you repeat a block of code multiple times without rewriting it.
Python's most common loop, for, iterates over a sequence like a list or
range of numbers.
for i in range(5):print(i)
Functions
A function is a reusable block of code that performs a specific task, defined once and called whenever needed. Functions help avoid repeating code and make programs easier to organize and test.
def add(a, b):return a + bresult = add(4, 6)
Data Structures
Data structures organize and store collections of related data. Python's two most-used built-in structures are lists (ordered collections) and dictionaries (key-value pairs).
- Lists store ordered items, accessed by index:
nums = [ 1, 2, 3] - Dictionaries store key-value pairs, accessed by key:
person = { "name": "Ray"}
Choosing between them depends on whether you need to access data by position (list) or by a named label (dictionary).
File Handling
File handling lets a program read from or write to files stored on disk.
Python's built-in open() function, used with, safely opens a file and
automatically closes it afterward.
with open("file.txt") as f:data = f.read()print(data)
Opening a file in write mode ("w") instead of default read mode ("r") lets you save data to it.
Classes and OOP
Object-Oriented Programming (OOP) organizes code around objects — bundles of data (attributes) and behavior (methods) defined by a class, which acts as a blueprint.
class Student:def __init__(self, name):self.name = namedef greet(self):print(f"Hi, I'm {self.name}")s = Student("Ray")s.greet()
classdefines a blueprint for creating objects__init__runs automatically when an object is created, setting its initial attributesselfrefers to the specific object calling the method