A Quick Reference for Beginners and Professionals
May 28, 2026
Abstract
Python is a high-level, interpreted, and general-purpose programming language. Its
design philosophy emphasizes code readability with the use of significant indentation. This
document serves as a complete reference sheet covering basic syntax, data types, control
structures, collections, and core functional paradigms.
Contents
1 Introduction and Setup 2
2 Variables and Basic Data Types 2
2.1 Type Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 Operators 2
3.1 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.2 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
4 Control Flow 3
4.1 Conditional Statements (if-elif-else) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4.2 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4.2.1 For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4.2.2 While Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
5 Core Data Collections 4
5.1 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5.2 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5.3 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5.4 Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
6 Functions 4
7 Error and Exception Handling 5
8 File Operations 5
1
, 1 Introduction and Setup
To verify your Python installation, check the version in your terminal:
1 $ python --version
A simple ”Hello, World!” program in Python is incredibly direct:
1 print ("Hello , World !")
2 Variables and Basic Data Types
Variables in Python do not require explicit declaration; they are dynamically typed and assigned
using the standard assignment operator (=).
1 # Integer
2 age = 25
3
4 # Float
5 pi = 3.14159
6
7 # String
8 name = " Alice "
9
10 # Boolean
11 is_active = True
12
13 # None ( represents the absence of a value )
14 result = None
2.1 Type Casting
You can convert variables between different types using built-in functions:
1 x = str (3) # x will be '3'
2 y = int (3.9) # y will be 3 ( truncated )
3 z = float (3) # z will be 3.0
3 Operators
Python supports standard arithmetic, comparison, and logical operators.
3.1 Arithmetic Operators
3.2 Logical Operators
Logical operations are written in plain English words: and, or, and not.
1 a = True
2 b = False
3
4 print (a and b) # False
5 print (a or b) # True
6 print (not a) # False
2