MODULE 01 · ← All Modules
FUNDAMENTALS OF PYTHON
01
Unit 1

Features, Identifiers & Keywords

Python is an interpreted, high-level, dynamically typed, object-oriented language created by Guido van Rossum (1991). Key features: simple syntax, portable, extensible, free/open-source, large standard library.

Identifier Rules

RuleValidInvalid
Letters, digits, underscore onlymy_var, x1my-var, x@1
Cannot start with digit_count, name1count, 2name
Case sensitiveAge ≠ age
Cannot be keywordmyifif, for, while

Python Keywords (35)

FalseNoneTrueandasassertasyncawaitbreakclasscontinuedefdelelifelseexceptfinallyforfromglobalifimportinislambdanotorpassraisereturntrywhilewithyield
02
Unit 1

Variables, Data Types & Type Conversions

TypeExampleNotes
intx = 10Unlimited precision integers
floatx = 3.1464-bit IEEE 754
complexx = 3+4jReal + imaginary part
strx = "hello"Immutable sequence of chars
boolx = TrueSubclass of int; True=1, False=0
listx = [1,2,3]Mutable ordered sequence
tuplex = (1,2,3)Immutable ordered sequence
dictx = {'a':1}Key-value pairs
setx = {1,2,3}Unordered, no duplicates

Type Conversion Functions

int("42")      # → 42
float(10)      # → 10.0
str(3.14)      # → "3.14"
bool(0)        # → False  (0, "", [], None → False; everything else → True)
list("abc")    # → ['a', 'b', 'c']
tuple([1,2])  # → (1, 2)
03
Unit 1–2

Operators, Precedence & Associativity

CategoryOperatorsExample
Arithmetic+ - * / // % **17//3=5, 17%3=2, 2**3=8
Comparison== != < > <= >=5 != 3 → True
Logicaland or notTrue and False → False
Assignment= += -= *= /= //= %=x += 5
Bitwise& | ^ ~ << >>5 & 3 = 1
Identityis, is notx is None
Membershipin, not in3 in [1,2,3]
Precedence (high→low): **~ + - (unary) → * / // %+ -<< >>&^| → comparison → notandor
Associativity: Left-to-right except ** (right-to-left)
04
Unit 3

Input, Output, Import & Math Functions

# input() always returns string
name = input("Enter name: ")
age  = int(input("Enter age: "))

# print() with sep and end
print("Hello", name, sep=", ", end="!\n")
print(f"Age: {age}")          # f-string (preferred)
print("%.2f" % 3.14159)     # → 3.14

# range(start, stop, step)
list(range(1, 10, 2))       # → [1, 3, 5, 7, 9]

math module

import math
math.sqrt(16)   # 4.0
math.ceil(4.2)  # 5
math.floor(4.9) # 4
math.pow(2,8)   # 256.0
math.log(100,10)# 2.0
math.factorial(5) # 120
math.pi          # 3.14159...
math.e           # 2.71828...
05
Unit 4

Decision-Making Structures

# if / elif / else
if x > 0:
    print("positive")
elif x == 0:
    print("zero")
else:
    print("negative")

# Ternary (conditional expression)
result = "even" if x % 2 == 0 else "odd"

# Nested if
if a > 0:
    if b > 0:
        print("both positive")
Python has no switch/case (pre-3.10). Use if/elif chains or a dict mapping. Python 3.10+ has match/case.
06
Unit 5

Looping Structures

# while loop
i = 1
while i <= 5:
    print(i)
    i += 1

# for loop with range
for i in range(1, 6):
    print(i)

# for loop over iterable
for ch in "hello":
    print(ch)

# else on loop — runs if loop NOT broken
for i in range(5):
    print(i)
else:
    print("done")
Nested loops: Time complexity multiplies. O(n²) for two nested loops each running n times.
07
Unit 6

Control Statements

StatementEffectWorks In
breakExit loop immediatelyfor, while
continueSkip rest of current iterationfor, while
passDo nothing (placeholder)Anywhere
# break — find first even
for i in range(10):
    if i % 2 == 0:
        print(i); break

# continue — skip odd
for i in range(5):
    if i % 2 != 0: continue
    print(i)          # 0 2 4

# pass — empty function body
def todo():
    pass
FC
Quick Review

Flashcards — Module I

Tap to flip