Overview
Python is a programming language that is easy to read and write, which makes it a great choice for beginners. At the same time, it is powerful enough for professionals working in web development, data science, machine learning, automation, and much more.
Install Python using uv
Section titled “Install Python using uv”-
Install Scoop
Open PowerShell and run:
Terminal window Set-ExecutionPolicy RemoteSigned -Scope CurrentUserirm get.scoop.sh | iexOfficial site: https://scoop.sh
-
Install uv
Terminal window scoop install uv -
Verify installation
Terminal window uv --version -
Install Python
Terminal window uv python install 3.12
-
Install uv
Terminal window curl -LsSf https://astral.sh/uv/install.sh | sh -
Verify installation
Terminal window uv --version -
Install Python
Terminal window uv python install 3.12
Important uv Commands
Section titled “Important uv Commands”uv init my-project # create projectuv venv # create virtual environmentuv pip install <package> # install packageuv pip uninstall <pkg> # remove packageuv pip freeze # list installed packagesuv run python main.py # run scriptuv pip compile # lock dependenciesuv pip sync # install exact dependenciesuv pip show <package> # show package infouv run --python <version> <command> # run command with specific Python versionuv export --no-hashes > requirements.txt # export dependencies to requirements.txtIntroduction to Coding World with Python
Section titled “Introduction to Coding World with Python”Start here if you are brand new to Python. This section helps you understand how Python works and how to actually run your code.
- Python overview - simple, readable, and beginner-friendly
- Installation and setup using
uv - Running code:
- REPL (an interactive shell where you type and run code line by line)
- Script execution (writing code in
.pyfiles and running them)
print("Hello, World!")Project Structure
Section titled “Project Structure”As your project grows, it helps to organise your files in a clear way so they are easy to find and maintain.
my_project/│├── pyproject.toml # Project config (uv + dependencies)├── uv.lock # Auto-generated lock file├── README.md├── .gitignore├── .env # Environment variables│├── src/ # Main source code (recommended layout)│ └── my_project/│ ├── **init**.py│ ├── main.py # Entry point│ ││ ├── core/ # Core logic (business logic)│ │ ├── **init**.py│ │ └── config.py # Settings, env handling│ ││ ├── services/ # External interactions / logic layer│ │ ├── **init**.py│ │ └── api.py│ ││ ├── models/ # Data models│ │ ├── **init**.py│ │ └── user.py│ ││ ├── utils/ # Helper functions│ │ ├── **init**.py│ │ └── helpers.py│ ││ └── db/ # Database layer│ ├── **init**.py│ └── sqlite.py│├── tests/ # Testing (pytest)│ ├── **init**.py│ ├── test_main.py│ ├── test_services.py│ └── conftest.py # Fixtures│├── scripts/ # CLI / automation scripts│ └── run.py│└── logs/ # Log files (optional)Data Types in Python
Section titled “Data Types in Python”In Python, every piece of data has a type. Understanding types is one of the most important foundations to get right as a beginner.
- Numeric types:
int(whole numbers),float(decimal numbers),bool(True or False) - Strings:
str(text) - Collections - ways to group multiple values together:
list(ordered, can be changed)tuple(ordered, cannot be changed)set(only unique elements, no duplicates)dict(pairs of keys and values)
- Type conversion - changing one type to another:
int(),str(), etc.
Conditionals in Python
Section titled “Conditionals in Python”Conditionals let your program make decisions - doing one thing if something is true and something else if it is not.
if,elif,else- basic decision making- Nested conditions - checking multiple things at once for more complex logic
- Logical operators:
and,or,not- combine or flip conditions - Ternary operators - writing a simple if/else on a single line
- Best practices - how to write conditions that are easy to read
Loops in Python
Section titled “Loops in Python”Loops let you repeat a block of code automatically instead of writing it out many times.
forloop - go through each item in a list or sequence one by onewhileloop - keep running as long as a condition is true- Control statements that change how a loop behaves:
break- stop the loop immediatelycontinue- skip the current step and go to the next onepass- do nothing (used as a placeholder)
Functions in Python
Section titled “Functions in Python”Functions let you group code into reusable blocks. Instead of writing the same code over and over, you write it once as a function and call it whenever you need it.
- Defining functions using
def- how to create a function - Parameters and return values - passing data in and getting data out
- Default arguments - making some parameters optional with a default value
- Variable arguments:
*args,**kwargs- accepting any number of arguments - Recursion - a function that calls itself to solve a problem step by step
- Lambda functions - tiny, one-line anonymous functions for simple tasks
- Command-line arguments - passing values to your script when you run it
- Higher-order functions:
map(),filter(),reduce()- functions that work on other functions - Scope and variable resolution - understanding where a variable can be accessed (LEGB rule)
- Docstrings - writing descriptions inside your functions so others know what they do
Comprehensions in Python
Section titled “Comprehensions in Python”Comprehensions are a short, clean way to create lists, dictionaries, and sets without writing a full loop.
- List comprehension - build a list in one line
- Dictionary comprehension - build a dictionary in one line
- Set comprehension - build a set in one line
- Generator expressions - like list comprehensions but they only produce values one at a time, saving memory
Generators and Decorators in Python
Section titled “Generators and Decorators in Python”These are slightly more advanced tools that help you write cleaner and more efficient code.
- Generators:
- Use
yieldto produce values one at a time instead of all at once - Use much less memory than building a full list
- Use
- Generator expressions - a short way to write a generator
- Decorators:
- Wrap a function to add extra behaviour without changing its code
- Common real-world uses: logging, checking if a user is logged in (auth)
Object Oriented Programming in Python
Section titled “Object Oriented Programming in Python”OOP is a way of organising code by grouping related data and actions together into “objects.” This makes large programs much easier to manage and grow over time.
- Classes and objects - the main building blocks
__init__constructor - runs when a new object is created and sets it up- Instance vs class variables - data that belongs to one object vs data shared by all objects
- Methods - functions that belong to an object and describe what it can do
Core Principles
Section titled “Core Principles”- Encapsulation - keeping data and the code that uses it together, and hiding internal details
- Inheritance - one class can reuse code from another class
- Polymorphism - different classes can share the same method name but behave differently
- Abstraction - hiding the complicated parts and only showing what the user needs
Advanced Techniques
Section titled “Advanced Techniques”- Magic methods:
__str__,__repr__,__len__- special built-in methods that control how your object behaves - Property decorators - a clean way to write getters and setters
dataclasses- a shortcut for creating simple classes that mainly hold data- Metaclasses - advanced control over how classes themselves are created
File and Exception Handling in Python
Section titled “File and Exception Handling in Python”Almost every real program reads files or runs into errors. This section teaches you how to handle both safely.
- File handling operations:
- Read and write files using context managers (the
withstatement) - Work with text files, binary files, and CSV files
- Best practices for file input and output
- Read and write files using context managers (the
- Exception handling:
try,except,finallyblocks - catch and respond to errors without crashing- Common exception types and how they relate to each other
- Custom exceptions - create your own error types for your specific program
- How to recover from errors gracefully
- Logging strategies - recording what happened so you can debug later
Common Python Libraries
Section titled “Common Python Libraries”These are the most useful libraries you will come across in everyday Python development. Some come with Python already, others need to be installed.
System and File Operations:
os-> file system operations, reading environment variablessys-> interacting with the Python runtime, reading command-line argumentspathlib-> a modern, clean way to work with file pathsshutil-> copying, moving, and deleting files and folders
Data Serialization (converting data to/from storable formats):
json-> read and write JSON datacsv-> read and write CSV filespickle-> save and load Python objects directlyyaml-> read and write YAML format files
Database and Storage:
sqlite3-> a simple database that lives in a single filesqlalchemy-> a powerful library for working with databases using Python objects
Networking and APIs:
requests-> the easiest way to make HTTP calls (call APIs, fetch web pages)urllib-> a built-in alternative for HTTP requestshttp.server-> spin up a basic HTTP server
Date and Time:
datetime-> work with dates, times, and timezonestime-> simple time utilities like pausing your scriptschedule-> run tasks automatically at set times
Utilities:
itertools-> tools for working with loops and sequences more efficientlyfunctools-> tools for functional programming patternscollections-> special container types likeCounter,deque, anddefaultdict
Networking in Python
Section titled “Networking in Python”This section covers how programs talk to each other over a network - from low-level sockets to high-level HTTP calls.
Fundamentals:
- IP addresses and ports - how devices and services are identified on a network
- Sockets - the basic building block of any network connection
- TCP vs UDP protocols - two different ways of sending data (reliable vs fast)
- How data is packaged and routed across a network
Socket Programming:
- Creating a server socket that waits for connections
- Handling client connections when they arrive
- Sending and receiving data in both directions
- Non-blocking I/O - handling connections without freezing the program
HTTP and REST APIs:
- The request/response cycle - how a client and server talk
- HTTP methods: GET, POST, PUT, DELETE - what each one is used for
- Headers and status codes - extra information about requests and responses
- Authentication and tokens - proving who you are to an API
Using the requests Library:
- Making GET and POST requests
- Adding query parameters and headers
- Sending JSON data in a request body
- Handling errors and retrying failed requests
- Using sessions for multiple requests to the same server
Multithreading, Multiprocessing, and GIL
Section titled “Multithreading, Multiprocessing, and GIL”This section explains how Python handles doing more than one thing at a time, and what the limits are.
Multithreading:
- Threading basics - running multiple tasks at the same time within one program
- Creating threads - starting and managing them
- Race conditions - what happens when two threads try to change the same data at once
- Locks and synchronization - tools to prevent race conditions
- Thread pools - a smarter way to manage many threads
- Daemon threads - background threads that stop when the main program ends
Multiprocessing:
- Process vs thread - the key differences and when to use each
- Process creation - running code in a completely separate process for true parallelism
- Sharing data between processes
- Inter-process communication (IPC) - how separate processes send messages to each other
- When multiprocessing is a better choice than threading
Global Interpreter Lock (GIL):
- What the GIL is - a lock inside CPython that only lets one thread run Python code at a time
- How it affects concurrency - threads cannot truly run in parallel for CPU-heavy tasks
- The difference between CPU-bound tasks (affected by GIL) and I/O-bound tasks (not much affected)
Asyncio in Python
Section titled “Asyncio in Python”Asyncio is Python’s built-in way of handling many tasks at once without using threads. It works especially well when your program spends a lot of time waiting - like waiting for an API response or a file to load.
- Coroutines:
asyncandawaitkeywords - how you write async code in Python- How to define and run an async function
- The coroutine protocol - how Python knows a function is async
- Event loop:
- The engine that drives async code - it keeps checking which tasks are ready to run
- Task scheduling - deciding what runs next
- Non-blocking I/O - waiting for something without freezing everything else
- Async tasks:
- Creating and managing tasks that run at the same time
- Task groups and running multiple tasks together
- Cancelling tasks and setting timeouts
- Practical patterns:
- I/O-bound operations like network calls and file reads
- CPU-bound tasks should use multiprocessing instead of asyncio
- Async context managers - using
within async code - Handling errors in async code
Testing in Python
Section titled “Testing in Python”Testing means writing extra code that checks your main code works correctly. It might feel like extra work at first, but it saves you a lot of time debugging later.
Assertion Testing:
assertstatements - the simplest way to check that something is true- Common assertion patterns for testing conditions
unittest Framework:
- Test cases and test suites - how to organise your tests
- Setup and teardown methods - run code before and after each test
- Test discovery - automatically finding all your test files
- Assertions and comparisons - the built-in tools for checking results
- Mocking and patching - replacing real dependencies with fake ones during tests
pytest Framework (Recommended):
- Writing simple test functions - no need for a class
- Fixtures - reusable setup code shared between tests
- Test discovery - automatically finding tests
- Parametrized testing - running the same test with many different inputs
- Markers and test categories - grouping and filtering tests
- Command-line options for running specific tests
- Works well with CI/CD tools like GitHub Actions
Best Practices:
- Test coverage - measuring how much of your code is tested
- TDD (Test-Driven Development) - writing tests before you write the code
- Mocking external dependencies - replacing APIs, databases, etc. with fake versions in tests
- Integration vs unit tests - knowing the difference and when to use each
These are the core topics and tools you need to get started with Python. Work through them one by one and you will build the skills to create everything from small automation scripts to full web applications. Happy coding!