Python Week 1 - Cheat Notes
Days 1–5 Quick Reference
Setup · Syntax · Data Types · Operators
Day 1 - Setting Up Your Python Environment
The 4 Tools & Why They Exist
Tool What It Does Key Benefit
Anaconda Installs Python + package manager + 250 No manual setup; everything works
libraries in one go out of the box
VS Code Code editor with syntax highlighting, Write and run Python without leaving
autocomplete & built-in terminal the editor
Virtual Env Isolated Python environment per project Prevents library version conflicts
(venv/conda) between projects
Project Structure Organised folders: week1/, week2/, .env, Code is readable, shareable, and
[Link] easy to debug
Essential Commands
Conda (Anaconda)
conda create --name py_course python=3.11 # create env (once)
conda activate py_course # activate (every session)
conda deactivate # exit env
conda install numpy # install a library
conda env list # list all environments
Verification
conda --version # check Anaconda installed
python --version # check Python version
Project Structure
python_course/
├── week1/
│ ├── day1_hello.py
│ └── day2_variables.py
├── week2/
├── .env # secret keys - never share
└── [Link] # library list
Golden Rule: Before writing any code - (1) Is the right environment active? (2) Am I in the right folder? These two
checks prevent 90% of beginner setup issues.
Day 2 - Syntax, Variables & print()
Syntax vs Semantics
Term Meaning Example
Syntax Grammar rules - how code must be written if x > 0: (colon required)
Semantics What the code actually does at runtime x = 5 means store 5 in x
Indentation
• Use 4 spaces per level (PEP 8 standard)
• Never mix spaces and tabs
• Indentation always follows a colon : (if, for, while, def, class)
if age >= 18:
print('Adult') # 4 spaces
else:
print('Minor') # 4 spaces
Comments
Type Syntax Use
Single-line # comment text Notes, disabling code
Multi-line """ ... """ or ' ' ' ... ' ' ' Block notes, file headers
Docstring def fn():\n """What this does.""" Documents functions - accessible via help()
Write WHY, not WHAT. Bad: # x = x / 1000 | Good: # convert ms to seconds
Variables & Data Types
Type Example Used For
int age = 25 Whole numbers
float price = 9.99 Decimal numbers
str name = "Alice" Text (always in quotes)
bool is_on = True True or False only
Multiple assignment shortcuts:
a, b, c = 1, 2, 3 # assign in one line
x = y = z = 0 # same value to multiple vars
a, b = b, a # swap two variables
Naming Conventions
Style Example Use For
snake_case student_name Variables and functions (most common)
UPPER_SNAKE_CASE MAX_SIZE Constants
CamelCase StudentProfile Class names
• Must start with a letter or underscore - not a digit
• No spaces or hyphens - use underscores only
• Cannot be a Python keyword (if, for, while, def, class…)
• Case-sensitive: name, Name, and NAME are three different variables
print() Reference
Parameter Default What It Does Example
sep ' ' (space) Separator between values print(1,2,3, sep='-') → 1-2-3
end '\n' (newline) What to print at the end print('Hi', end='!') → Hi!
f-strings (recommended - Python 3.6+):
name = "Alice"; age = 25; gpa = 3.856
print(f"Hello, {name}!") # Hello, Alice!
print(f"Age next year: {age + 1}") # Age next year: 26
print(f"GPA: {gpa:.2f}") # GPA: 3.86
Running Python Files
Action Windows macOS / Linux
Run file python [Link] python3 [Link]
Check version python --version python3 --version
Clear terminal cls clear
Day 3 - Data Types, Type Conversion & f-Strings
The 4 Core Types
Type Example Sales Use Case
int lead_count = 42 Number of leads, deal count, days in pipeline
float deal_value = 250000.00 Revenue, percentages, conversion rate
str "Rajesh Kumar" Lead name, stage, company, email
bool is_active = True Is the deal active? Has the email been sent?
print(type(lead_count)) # <class 'int'>
Strings need quotes - numbers don't. deal_value = 250000 (int) vs deal_value = "250000" (str). Python can do
maths with the first, NOT the second.
Type Conversion (Casting)
Python never converts types automatically - you must do it explicitly.
Function Example Result When to Use
int(x) int("42") 42 User-typed numbers (input() always returns
str)
float(x) float("99.5") 99.5 CSV percentages stored as strings
str(x) str(250000) "250000" Joining a number with text
bool(x) bool(0), bool("") False Check if a field has data
round(x, n) round(3.14159, 2) 3.14 Round to n decimal places
int(99.9) = 99 - it TRUNCATES, it does NOT round. Use round(99.9) to get 100.
Common pattern - input() always returns a string:
user_input = input("Enter deal value: ") # returns str!
deal_value = int(user_input) # convert before maths
f-String Format Specifiers
Specifier Example Output
{value:,} f"{250000:,}" 2,50,000 (comma separators)
{value:.2f} f"{99.567:.2f}" 99.57 (2 decimal places)
{value:.1%} f"{0.6733:.1%}" 67.3% (percentage)
{expr} f"{price * 1.18:.2f}" Expressions work directly inside {}
Multiline f-string template:
summary = f"""
Name : {lead_name}
Value : Rs.{deal_value:,}
Stage : {stage}
"""
Day 3 Key Takeaways
• Every value has a type. Use type() to check.
• input() ALWAYS returns a string - convert before doing any maths.
• float → int truncates: int(99.9) = 99, not 100. Use round() for proper rounding.
• f-strings are the cleanest way to format output. Format specifiers go inside {} after a colon.
Day 4 - Operators: Arithmetic, Comparison & Logical
01 · Arithmetic Operators
Operator Symbol Example Result Note
Addition + 250000 + 50000 300000
Subtraction - 500000 - 75000 425000
Multiplication * 250000 * 1.18 295000.0
Division / 300000 / 3 100000.0 Always returns float
Floor division // 7 // 2 3 Drops decimal (no
rounding)
Modulo % 7%2 1 Remainder after division
Exponent ** 2 ** 10 1024 Rarely used in everyday
scripts
Augmented assignment shortcuts:
total += 250000 # same as total = total + 250000
total *= 1.18 # same as total = total * 1.18
BODMAS applies in Python. Use brackets to make intent clear: (250000 + 50000) * 0.18, not 250000 + 50000 *
0.18
02 · Comparison Operators
Always return True or False.
Operator Symbol Example Plain English
Equal to == stage == "Closing" Is the stage exactly Closing?
Not equal to != stage != "Lost" Is the deal still alive?
Greater than > deal_value > 100000 Is this a high-value deal?
Less than < days_open < 30 Is this deal still fresh?
Greater or equal >= win_rate >= 0.5 Is win rate at least 50%?
Less or equal <= discount_pct <= 10 Is discount within policy?
CRITICAL: = assigns a value. == compares two values. Writing = when you mean == is the #1 beginner error.
Safe string comparison (handle spaces + case):
stage_raw = " Closing "
stage_raw.strip().lower() == "closing" # True - always normalise first
03 · Logical Operators
Operator Returns True When… Example
and BOTH conditions are True deal_value > 100000 and stage == "Closing"
or AT LEAST ONE condition is True stage == "Closing" or stage == "Negotiation"
not The condition is False not stage == "Lost"
Combining all three:
qualified = (deal_value > 100000
and days_open < 60
and discount_pct <= 10
and is_active)
Bonus - in operator (check membership):
stage in ["Closing", "Negotiation"] # cleaner than two == with or
Day 4 Key Takeaways
• 7 arithmetic operators - the unusual ones: // (floor), % (remainder), ** (exponent). Use += shorthand.
• Comparison operators always return True or False. CRITICAL: = assigns, == compares.
• Logical operators and / or / not combine conditions. Use brackets for readability.
• Always .strip().lower() strings before comparing when data comes from users or CSVs.
• Short-circuit evaluation: and stops at first False, or stops at first True - put cheapest checks first.
Day 5 - Conditionals & Loops
01 · Conditionals (if / elif / else)
• Control the flow of the program based on logic.
if deal_value >= 100000 and stage != 'Lost':
print('HIGH Priority')
elif deal_value >= 50000:
print('NURTURE')
else:
print('DROP')
Nested Conditions:
if stage == 'Qualified':
if deal_value > 50000:
print('Send proposal')
else:
print('Assign to Junior Rep')
Python uses indentation to figure out what code belongs inside the 'if' block. Always use 4 spaces.
02 · Loops (for / while)
Loop Type When to Use Example
for When you know how many times to repeat for lead in leads:
while When you wait for a condition to change while is_active:
The range() function:
for i in range(5): # Loops 5 times (0 to 4)
for i in range(1, 6): # Loops from 1 to 5
for i in range(0, 10, 2): # Counts by 2 (0, 2, 4, 6, 8)
03 · Loop Controls (break / continue)
Keyword What it does Sales Use Case
break Stops the loop entirely Stop searching when the lead is found
continue Skips the rest of the current loop Skip processing if lead stage is 'Lost'
Real-world Example:
for stage in ['New', 'Lost', 'Qualified', 'Lost', 'Won']:
if stage == 'Lost':
continue # Skip Lost leads
if stage == 'Won':
print('Target hit!')
break # Stop looking further
print(f'Processing {stage} lead...')
Day 5 Key Takeaways
• Use if/elif/else to branch logic. Order matters: Python stops at the first True condition.
• for loops iterate over a known sequence (lists, range). while loops run until a condition turns False.
• break entirely escapes the loop. continue just jumps to the next item.
Master Quick-Reference Cheatsheet
Data Types & Conversion
x = 42 # int
y = "hello" # str
z = 3.14 # float
b = True # bool (capital T/F)
int("42") # 42
float("3.14") # 3.14
str(42) # '42'
bool(0) # False | bool('') # False
round(3.14159, 2) # 3.14
f-String Cheatsheet
name = "Rajesh"; value = 250000; rate = 0.673
print(f"Name: {name}") # Name: Rajesh
print(f"Value: Rs.{value:,}") # Rs.2,50,000
print(f"Rate: {rate:.1%}") # 67.3%
print(f"Dec: {value:.2f}") # 250000.00
print(f"Math: {value * 1.18:,.2f}") # 2,95,000.00
Operators at a Glance
# ARITHMETIC
a + b a - b a * b a / b a // b a % b a ** b
x += 5 x -= 5 x *= 2 x /= 2
# COMPARISON - always True or False
a == b a != b a > b a < b a >= b a <= b
# LOGICAL
a and b a or b not a
# MEMBERSHIP
stage in ["Closing", "Negotiation"]
Virtual Environment Quick-Start
conda create --name py_course python=3.11
conda activate py_course
conda install numpy pandas
# Always activate before writing code!
The Golden Workflow: Activate env → navigate to folder → open VS Code → write code → run file. Every day, in
that order.