Chapter 14: Quick Reference Sheet
Data Types Quick Reference
| Type | Syntax | Example | Mutability |
|---|---|---|---|
| Integer | int | 42, -1, 0 | Immutable |
| Float | float | 3.14, -0.5, 1e3 | Immutable |
| String | str | "hello", 'world' | Immutable |
| Boolean | bool | True, False | Immutable |
| List | list | [1, 2, 3] | Mutable |
| Tuple | tuple | (1, 2, 3) | Immutable |
| Dictionary | dict | Mutable | |
| Set | set | Mutable | |
| None | NoneType | None | Immutable |
Common String Operations
s = "Hello, Python!"
# Common methods
s.lower() # "hello, python!"
s.upper() # "HELLO, PYTHON!"
s.strip() # Remove leading/trailing whitespace
s.split(", ") # ["Hello", "Python!"]
s.replace("Hello", "Hi") # "Hi, Python!"
s.find("Python") # 7 (returns index position)
s.startswith("Hello") # True
s.endswith("!") # True
",".join(["a","b","c"]) # "a,b,c"List/Dictionary Comprehensions
# List comprehensions
[x ** 2 for x in range(10)] # Squares
[x for x in range(20) if x % 2 == 0] # Filtering
[x.upper() for x in ["hello", "world"]] # Transformation
# Dictionary comprehensions
{k: v for k, v in zip(["a","b","c"], [1,2,3])} # {"a":1,"b":2,"c":3}
{x: x**2 for x in range(5)} # {0:0, 1:1, 2:4, ...}
# Set comprehensions
{x % 3 for x in range(10)} # {0, 1, 2}Common Built-in Functions
| Function | Purpose | Example |
|---|---|---|
| print() | Output | print("hi") |
| input() | Input | name = input("Name: ") |
| len() | Length | len([1,2,3])→ 3 |
| range() | Number sequence | range(5)→ 0,1,2,3,4 |
| type() | Check type | type(42)→ <class 'int'> |
| int/float/str() | Type conversion | int("42")→ 42 |
| sorted() | Sort | sorted([3,1,2])→ [1,2,3] |
| enumerate() | Iterate with index | enumerate(["a","b"]) |
| zip() | Parallel iteration | zip([1,2],["a","b"]) |
| map() | Map | map(str, [1,2,3]) |
| filter() | Filter | filter(bool, [0,1,"",2]) |
| isinstance() | Type check | isinstance(42, int)→ True |
| dir() | View attributes | dir([]) |
| help() | Help documentation | help(print) |
f-string Formatting Quick Reference
name = "Python"
version = 3.12456
pi = 3.14159265
f"Hello, {name}!" # "Hello, Python!"
f"Version: {version:.2f}" # "Version: 3.12"
f"Pi: {pi:.4f}" # "Pi: 3.1416"
f"Right aligned: {42:>10}" # "Right aligned: 42"
f"Left aligned: {42:<10}" # "Left aligned: 42 "
f"Centered: {42:^10}" # "Centered: 42 "
f"Zero padded: {42:05d}" # "Zero padded: 00042"
f"Percentage: {0.856:.1%}" # "Percentage: 85.6%"
f"Large number: {1234567:,}" # "Large number: 1,234,567"
f"Binary: {42:b}" # "Binary: 101010"
f"Hex: {255:x}" # "Hex: ff"Common Terminal Commands
# Python execution
python script.py # Run a script
python -m venv venv # Create virtual environment
python -c "print('hi')" # Execute code directly
python -m http.server 8000 # Quick HTTP server
python -m json.tool file.json # Format JSON
# pip operations
pip install package_name # Install package
pip install -r requirements.txt # Batch install
pip freeze > requirements.txt # Export dependencies
pip list --outdated # View upgradable packages
# Debugging
python -i script.py # Enter interactive mode after execution
python -m pdb script.py # Start debugger
python -m cProfile script.py # Performance profilingLearning Roadmap 🗺️
📝 Note: 📝 Recommended learning path: Fundamentals (1-2 weeks) — Master chapters 1-6 of this guideAdvanced Syntax (1-2 weeks) — Object-oriented programming, file operations, exception handlingStandard Library Practice (1 week) — Get familiar with os, re, datetime and other common modulesChoose a direction: 🌐 Web Development → Learn Flask/Django📊 Data Analysis → Learn pandas, numpy, matplotlib🤖 AI/ML → Learn PyTorch, scikit-learn🔧 Automation → Learn selenium, requests, scheduleProject Practice (ongoing) — Build real projects, contribute to open source, accumulate experience
Recommended Learning Resources
| Resource | Type | Audience |
|---|---|---|
| Python Official Documentation (Chinese) | Docs | Everyone |
| Liao Xuefeng Python Tutorial | Tutorial | Beginners |
| Python 100 Days | Projects | After learning basics |
| "Python Crash Course" | Book | Absolute beginners |
| LeetCode | Coding Practice | Algorithm practice |
💡 Tip: 🎉 Congratulations on finishing this tutorial! Remember, programming is a "craft" — you can't learn it just by reading. Now open your terminal, type python3, and start practicing! Every programmer started by writing print("Hello"). Happy coding! 🚀