🐍 Python Quick Reference Card
Module 1: What is Python & Getting Started
What is Python?
High-level: Handles complexity for you
Interpreted: Runs line by line
Dynamically typed: No type declarations
Indentation-based: Whitespace matters!
Created By
Guido van Rossum in 1991
Named after Monty Python (not the snake!)
We use Python 3 (Python 2 retired 2020)
The print() Function
print("Hello, World!")
# Multiple items (adds spaces)
print("Age:", 25)
# Math in print
print("Sum:", 3 + 4)
# Empty line
print()
Comments
print("Hi") # Inline comment
# print("Commented out code")
Comments start with #
Python ignores everything after #
Use comments to explain why, not what
Strings (Text)
"Hello"
'Hello'
# Apostrophes? Use double quotes
"It's fun"
# Quote marks? Use single quotes
'She said "hi"'
Arithmetic Operators
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 10 - 4 | 6 |
* | Multiplication | 6 * 7 | 42 |
/ | Division | 15 / 4 | 3.75 |
// | Integer Div | 15 // 4 | 3 |
% | Modulo | 15 % 4 | 3 |
** | Power | 2 ** 3 | 8 |
// rounds DOWN to int
Data Types (Preview)
| Type | Name | Examples |
|---|---|---|
| int | Integer | 42, -7, 0 |
| float | Decimal | 3.14, -0.5 |
| str | String | "hello", '42' |
| bool | Boolean | True, False |
type("42") # <class 'str'>
The REPL
Read → Eval → Print → Loop
Start: type python in terminal
Exit: type exit() or quit()
Prompt: >>> means ready for input
Running Python
Script File
Save as filename.py
Run: python filename.py
In IDLE: press F5
File Naming Rules
Use .py extension
Lowercase + underscores
No spaces in names
Never name it python.py!
Useful Functions
type() # Check data type
help() # Get documentation
exit() # Leave the REPL
Common Errors to Avoid
- Print() instead of print() (case!)
- Mismatched quotes: "hello'
- Missing parentheses: print "hi"
- Forgetting quotes around text
- Naming file python.py
- Not adding Python to PATH