SAMANTUS Python for Data Analytics — Complete Training Manual CHEAT SHEET 01
← Back to Course Index

Python Cheat Sheet


On This Page

Bonus Chapter: Python Cheat Sheet


A quick, print-friendly reference for the core Python syntax covered in Modules 1-12. Pin this to your desk while practicing!

CS1.1  Variables & Data Types

TypeExample
intage = 28
floatprice = 499.99
strname = "Samantus"
boolis_active = True
Type checktype(x)
Type castint(x), float(x), str(x)

CS1.2  Operators

CategoryOperators
Arithmetic+ - * / // % **
Comparison== != > < >= <=
Logicaland or not
Assignment= += -= *= /=
Membershipin / not in
Identityis / is not

CS1.3  Control Flow

► Conditionals & Loops
if condition:
    ...
elif other_condition:
    ...
else:
    ...

for item in sequence:
    ...

while condition:
    ...

# break, continue, pass control loop flow

CS1.4  Functions

► Function Syntax
def greet(name, course="SEO"):   # default parameter
    return f"{name} - {course}"

square = lambda x: x * x         # lambda function

def factorial(n):                 # recursion
    if n <= 1: return 1
    return n * factorial(n-1)

CS1.5  Data Structures Quick Reference

StructureSyntaxMutable?Ordered?
List[1,2,3]YesYes
Tuple(1,2,3)NoYes
Set{1,2,3}YesNo
Dict{'a':1}YesYes (3.7+)

CS1.6  String Methods

MethodPurpose
upper() / lower()Change case
strip()Remove leading/trailing spaces
split(sep)Split into a list
join(list)Join list into a string
replace(a,b)Replace substring
find(sub)Find index of substring
startswith() / endswith()Check prefix/suffix
f-stringf"{variable}"

CS1.7  List Methods

MethodPurpose
append(x)Add to end
insert(i,x)Insert at index
remove(x)Remove first match
pop(i)Remove & return item at index
sort() / reverse()Sort or reverse in place
index(x) / count(x)Find index / count occurrences
List comprehension[x*2 for x in nums if x>0]

CS1.8  Exception Handling

► try-except-else-finally
try:
    risky_code()
except ValueError as e:
    print("Error:", e)
else:
    print("No errors occurred")
finally:
    print("Always runs")
ℹ Reminder
Full explanations and worked examples for every item on this sheet are in Modules 1-12 of the main training manual.