Skip to content

Chapter 14: Quick Reference Sheet

Data Types Quick Reference

TypeSyntaxExampleMutability
Integerint42, -1, 0Immutable
Floatfloat3.14, -0.5, 1e3Immutable
Stringstr"hello", 'world'Immutable
BooleanboolTrue, FalseImmutable
Listlist[1, 2, 3]Mutable
Tupletuple(1, 2, 3)Immutable
DictionarydictMutable
SetsetMutable
NoneNoneTypeNoneImmutable

Common String Operations

bash
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

bash
# 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

FunctionPurposeExample
print()Outputprint("hi")
input()Inputname = input("Name: ")
len()Lengthlen([1,2,3])→ 3
range()Number sequencerange(5)→ 0,1,2,3,4
type()Check typetype(42)→ <class 'int'>
int/float/str()Type conversionint("42")→ 42
sorted()Sortsorted([3,1,2])→ [1,2,3]
enumerate()Iterate with indexenumerate(["a","b"])
zip()Parallel iterationzip([1,2],["a","b"])
map()Mapmap(str, [1,2,3])
filter()Filterfilter(bool, [0,1,"",2])
isinstance()Type checkisinstance(42, int)→ True
dir()View attributesdir([])
help()Help documentationhelp(print)

f-string Formatting Quick Reference

bash
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

bash
# 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 profiling

Learning 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

ResourceTypeAudience
Python Official Documentation (Chinese)DocsEveryone
Liao Xuefeng Python TutorialTutorialBeginners
Python 100 DaysProjectsAfter learning basics
"Python Crash Course"BookAbsolute beginners
LeetCodeCoding PracticeAlgorithm 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! 🚀