A concise and practical cheat sheet, covering over 95% of all Python 3.x commands with examples. Designed for both Python developers, learners, and hobbyists. It provides quick answers and efficient learning without overwhelming you with details. This cheat sheet summarizes key Python syntax, concepts, and common functions in a compact PDF format.
π Download the Python Cheat Sheet (PDF)
- π§ Data Types & Data Type Conversions
- π€ Booleans & Strings
- β Operator Precedence
- π¨οΈ Print Functions & π§βπ» User Input
- π Decision Structure
- π Repetition Structures
β οΈ Exceptions- π Files & Strings
- π§° Functions & Modules
- π§΅ List, Dict, Set, Tuple
Data Types
- Text Type:
str - Numeroc Type:
int,float,complex - Boolean Type:
bool - Sequence Types: List (
list), Tuple (tuple), Range (range) - Set Type: Set (
set) - Mapping Type: Dictionary (
dic)
Data Type Conversions
- Integer and Float Conversions:
float(),int() - Real to Complex Data Type Conversion:
complex() - Data Type Conversion with Strings:
int(),str() - Type Conversion to Tuples and Lists:
tuple(),list() - Type Conversion to Dictionaries and Sets:
set(),dict() - Convert Binary to Decimal:
bin(),int() - Convert Hexadecimal to Decimal:
hex(),int() - Convert Text to Decimal:
ord(),chr()
Booleans
- Booleans as Numbers
- Comparison Operators:
==,!=,<,>,<=,>= - Membership and Identity Operators:
in,not in,is,is not - Boolean Operators:
not,and,or - Operator Precedence
Print Function
print(),sepandendparameters
User Input
input()
Decision Structure
if-then-elif-elsestatements
Repetition Structures
whilestatementforstatement
Exceptions
FileNotFoundError,IndexError,KeyError,ModuleNotFoundError,NameError,SyntaxError,TypeError,ValueError,ZeroDivisionError
Modules
importstatementfrom... importstatement
Files
open(),close(),read(),readline(),readlines()- access modes:
read,write,append,create
Strings
- String Delimiters: single quotes, double quotes, triple single quotes, triple double quotes
- Escape Sequences
- String Operations: concatenation, repetition
- String Length:
len() - Unicode Code/Text Conversion:
ord(),chr() - String Membership:
in,not in - String Indexing
- String Slicing
- String Slicing Steps
- String Methods:
upper(),lower(),isupper(),islower(),count(),endswith(),find(),index(),isalnum(),isalpha(),isdecimal(),isdigit(),isnumeric(),strip(),rstrip(),lstrip(),split(),replace() - Iterating over Strings
Lists
- List Creation:
list() - List Comprehension
- List Indexing
- List Slicing
- List Length:
len() - List Membership:
in,not in - List Comparison:
==,!=,<,>,<=,>= - List Manipulation
- List Concatenation and Repetition
- Adding Elements:
append(),extend(),insert() - Removing Elements:
remove(),pop() - Deleting Elements:
del - List Counting, Searching, and Sorting:
count(),index(),reverse(),sort() - String-to-List and Back:
split(),join() - List Built-in Functions:
all(),any(),len(),list(),max(),min(),reversed(),sorted(),sum(),tuple(),zip() - Iterating over Lists
Tuples
- Tuple Creation:
tuple() - Tuple Unpacking
- Tuple Built-in Functions:
all(),any(),count(),enumerate(),filter(),index(),len(),list(),map(),max(),min(),next(),reversed(),slice(),sum(),sorted(),tuple(),zip() - Tuple Operations: indexing, slicing, concatenation, repetition, membership
- Iterating over Tuples
Sets
- Set Creation:
set() - Adding Elements:
add(),update() - Removing Elements:
remove(),discard() - Set Operations: union, intersection, difference, symmetric difference, subset, superset
- Iterating over Sets
Dictionaries
- Dictionary Creation:
dict() - Dictionary Length:
len() - Key Membership:
in,not in - Retrieving a Value Given a Key:
get() - Adding a Key/Value Pair
- Updating a Key/Value Pair
- Deleting a Key/Value Pair:
del() - Dictionary Methods:
get(),items(),keys(),pop(),popitem(),update(),clear() - Iterating over Dictionaries
Similarities & Differences
- Ordered
- Duplicates allowed
- Mutable
- Comparison
- Access elements
- Slicing
- Concatenation, Repetition
- Iteration
This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).
You are free to:
- Share β copy and redistribute the material
- Adapt β remix, transform, and build upon it
Under the following terms:
- Attribution β You must give appropriate credit
- NonCommercial β You may not use the material for commercial purposes
Feel free to suggest improvements or open an issue. Contributions are welcome!