Home

01 Quiz: Modern Python Implementation

exercises quiz chapter-01 python uv virtual-environments

Instructions


Question 1: Python’s Dominance

Why is Python considered the leading language for modern software development in 2025?

A) It’s the oldest programming language and has the most legacy code
B) It combines readability, versatility across domains, and the strongest AI/ML ecosystem
C) It’s the only language that can be used for web development
D) It requires the least amount of memory and runs faster than all other languages

Show Answer

Correct Answer: B

Python dominates because it offers an exceptional combination of human-readable syntax, applicability across virtually every domain (web, data science, AI, automation, scientific computing), and the most comprehensive ecosystem for AI/ML development. While it’s not the fastest language (D is incorrect) or the oldest (A is incorrect), its productivity and versatility make it the #1 choice for modern developers. Option C is wrong because many languages can do web development.


Question 2: Virtual Environments - The Core Problem

What fundamental problem do Python virtual environments solve?

A) They make Python code run faster by optimizing dependencies
B) They allow different projects to use different, potentially conflicting package versions in isolation
C) They automatically fix bugs in third-party packages
D) They compress Python code to save disk space

Show Answer

Correct Answer: B

Virtual environments solve the “dependency hell” problem where different projects need different versions of the same package. Without virtual environments, installing pandas 2.1.0 for Project B would overwrite pandas 1.5.0 needed by Project A, causing Project A to break. Virtual environments create isolated spaces where each project has its own dependencies. Options A, C, and D describe capabilities that virtual environments don’t provide.


Question 3: The Apartment Building Analogy

In the lecture’s apartment building analogy for virtual environments, what do the “apartments” represent?

A) Different Python files in your project
B) Different functions within your code
C) Isolated virtual environments for different projects
D) Different directories on your computer

Show Answer

Correct Answer: C

The apartment building analogy illustrates how virtual environments work: each apartment (virtual environment) has its own furniture (packages), residents (projects) don’t interfere with each other, and the building (your computer) can host many independent apartments. Each virtual environment is completely isolated, just like apartments in a building.


Question 4: What’s Inside a Virtual Environment?

When you create a virtual environment, where are the project’s installed packages actually stored?

A) In the global Python installation directory
B) In the .venv/lib/pythonX.X/site-packages/ directory
C) In the cloud on PyPI servers
D) In a compressed ZIP file

Show Answer

Correct Answer: B

Virtual environments create a local directory structure (typically .venv/) that contains a site-packages/ folder where all the project’s dependencies are installed. This is separate from the global Python installation, which is the whole point of isolation. The packages aren’t stored in the cloud (C) or in a compressed format (D), and they’re not in the global installation (A) because that would defeat the purpose of isolation.


Question 5: The Old Way vs. The New Way

Before modern tools like uv, how many manual steps did developers typically need to perform to set up and run a Python project with dependencies?

A) 1 step - just run the Python script
B) 2-3 steps - create environment and install packages
C) 6+ steps - create venv, activate, upgrade pip, install dependencies, run code, deactivate
D) It was impossible to manage dependencies before modern tools

Show Answer

Correct Answer: C

The traditional workflow required: (1) python -m venv .venv, (2) activate the environment (OS-specific command), (3) pip install --upgrade pip, (4) install all dependencies, (5) run your code, and (6) deactivate when done. This was slow, manual, and error-prone. Modern tools like uv collapsed this into a single command: uv run main.py. Option D is wrong because it was possible, just cumbersome.


Question 6: Understanding pyproject.toml

What is the primary purpose of the pyproject.toml file in modern Python projects?

A) To store your Python source code
B) To serve as the single source of truth for project metadata, dependencies, and build configuration
C) To track which files have been modified (like Git does)
D) To improve Python code execution speed

Show Answer

Correct Answer: B

pyproject.toml is the modern, standardized configuration file that contains everything about your project: metadata (name, version, authors), dependencies with version constraints, build system configuration, and tool settings. It replaces the fragmented old approach of having requirements.txt, setup.py, setup.cfg, and other separate files. It’s not for source code (A), version control (C), or performance optimization (D).


Question 7: Dependency Version Specifiers

What does the version specifier pandas>=2.1.0 mean in a pyproject.toml file?

A) Install exactly version 2.1.0 of pandas, no other version
B) Install pandas version 2.1.0 or any newer version
C) Install pandas version 2.1.0 or any older version
D) Install the 2.1.0 release candidate (pre-release) version

Show Answer

Correct Answer: B

The >= operator means “greater than or equal to,” so pandas>=2.1.0 allows pandas 2.1.0, 2.1.1, 2.2.0, 3.0.0, or any future version. This is generally recommended because it allows bug fixes and improvements while still ensuring a minimum version. Option A would be pandas==2.1.0 (exact version), C would be pandas<=2.1.0, and D is not what this notation means.


Question 8: Why uv is Revolutionary

What makes uv significantly faster than traditional Python package management tools like pip?

A) It uses quantum computing algorithms
B) It’s written in Rust (compiled, native code) with parallel operations and smart caching
C) It downloads fewer packages than pip
D) It skips dependency checking to save time

Show Answer

Correct Answer: B

uv achieves 10-100x speed improvements because it’s written in Rust (compiled to native machine code, not interpreted Python), performs parallel package downloads and installations, uses optimized file I/O, and implements smart global caching. It doesn’t use quantum computing (A), downloads the same necessary packages as pip (C), and importantly does check dependencies properly—that’s part of what makes it better (D is wrong and would be dangerous).


Question 9: The Three uv Workflows

Which uv workflow is considered the most professional approach for distributing Python applications?

A) uv run main.py - running scripts directly
B) Manual virtual environment with uv venv and uv sync
C) Named scripts defined in [project.scripts] section of pyproject.toml
D) Installing packages globally without virtual environments

Show Answer

Correct Answer: C

Named scripts (like defining road-viewer = "main:main" in pyproject.toml) represent the most professional approach because they create clean, memorable CLI commands, are the standard used by professional tools (pytest, black, ruff), enable distribution through package repositories, and clearly define entry points. Option A is great for development, B is good for debugging, but C is what production-ready Python projects use. Option D is never recommended.


Question 10: What uv run Actually Does

When you execute uv run main.py, which of the following does NOT happen?

A) uv reads pyproject.toml to understand project requirements
B) uv checks if a virtual environment exists and creates one if needed
C) uv installs any missing dependencies into the virtual environment
D) uv permanently modifies your global Python installation

Show Answer

Correct Answer: D

uv run works entirely with project-local virtual environments and never modifies your global Python installation—that’s the whole point of the tool! It does read pyproject.toml (A), manage the .venv/ directory (B), and install dependencies locally (C), but all changes are isolated to the project. Keeping the global Python installation clean and untouched is a fundamental principle of proper Python development.


Question 11: Script Python vs. Production Python

What is the PRIMARY difference between “Script Python” and “Production Python”?

A) Production Python uses a different programming language
B) Script Python works, but Production Python includes proper structure, packaging, documentation, and professional workflows
C) Production Python is always faster than Script Python
D) Script Python can only run on your personal computer

Show Answer

Correct Answer: B

The key difference isn’t the language (both use Python) or necessarily performance, but the engineering practices: Production Python has modular structure, proper packaging with pyproject.toml, documentation, type hints, testing, version control, and can be distributed and maintained by teams. Script Python might work for a quick task but lacks the structure needed for long-term maintenance, collaboration, and distribution. While C might sometimes be true and D might often be the case, B captures the essential professional distinction.


Question 12: Modern vs. Legacy uv Commands

Which of the following represents the MODERN, recommended way to add a package to your project with uv?

A) uv pip install package-name
B) pip install package-name
C) uv add package-name
D) Download the package manually and copy files

Show Answer

Correct Answer: C

uv add package-name is the modern, native uv command that automatically updates pyproject.toml, resolves dependencies properly, updates the lock file, and installs the package. Option A (uv pip install) exists for backward compatibility but doesn’t update pyproject.toml automatically. Option B uses pip without uv’s benefits. Option D is manual and error-prone. The lecture specifically emphasizes using native uv commands over pip-compatible ones.


Question 13: Learning From Zip Files

The lecture has you download a zipped project file, even though Git/GitHub is better. Why this pedagogical choice?

A) Zip files are actually superior to Git for professional projects
B) Learning to initialize a Git repo yourself teaches you how repositories are born, which you’ll need to understand even when cloning existing repos
C) The university’s Canvas system can only distribute zip files
D) It’s a mistake in the lecture that should have been corrected

Show Answer

Correct Answer: B

The lecture deliberately uses a zip file as a teaching tool—you start with the “old way,” initialize Git yourself, create a GitHub repository, and connect/push. This hands-on experience teaches you how repositories are created from scratch, which helps you understand what’s happening “under the hood” when you clone existing repos later. It’s like learning to ride a bike with training wheels before joining the Tour de France. Options A and D are incorrect, and C isn’t the pedagogical reason.


Question 14: Python Package Search Order

When Python looks for a package to import, in what order does it search?

A) Standard library → Current directory → System Python → Virtual environment
B) Virtual environment → System Python → Current directory → Standard library
C) Current directory → Virtual environment site-packages → System Python → Standard library
D) It randomly searches all locations simultaneously

Show Answer

Correct Answer: C

Python searches in this specific order: (1) Current directory where you run the script, (2) Virtual environment’s site-packages/ if a venv is active, (3) System Python’s site-packages/ for global installations, (4) Standard library for built-in modules. This order is why virtual environments work—by putting their site-packages/ earlier in the search path, packages installed there are found before global ones.


Question 15: Why Python Won - Technical Reasons

According to the lecture, which factor is NOT a primary reason for Python’s dominance?

A) Readability and productivity - syntax close to pseudocode
B) Versatility - one language for web, data, AI, automation, and more
C) Fastest execution speed compared to all other languages
D) Massive ecosystem with 500,000+ packages on PyPI

Show Answer

Correct Answer: C

Python is NOT the fastest language—compiled languages like C++ and Rust are much faster. Python dominates because of readability (A), versatility across all domains (B), and the enormous ecosystem (D), plus the AI/ML revolution where Python is the de facto standard. Python wins on developer productivity and ecosystem strength, not raw execution speed. The tradeoff is intentional: slower execution but faster development.


Question 16: Professional Project Configuration

In Step 3 of the setup guide, you’re asked to replace the author name in pyproject.toml with your GitHub username. Why does this matter?

A) The code won’t run if you don’t change it
B) It teaches proper attribution for open source and professional projects - you’re the author of your version
C) GitHub will reject your push if the author doesn’t match your username
D) It’s just busy work with no real purpose

Show Answer

Correct Answer: B

Updating the author field teaches you about proper attribution in software development. When you publish packages or contribute to open source, correct authorship is crucial for credit, licensing, legal compliance, and professional reputation. The code will run fine without changing it (A is false), GitHub doesn’t enforce author matching (C is false), and it has clear pedagogical purpose (D is false). It’s about developing professional habits early.


Question 17: The Evolution of Python Package Management

The lecture describes three eras of Python package management. What represents the “Modern Era”?

A) pip + venv (2013-2023) - separate tools, slow, no lock files
B) Poetry/Pipenv (2018-2024) - integrated tools but still Python-based and slow
C) uv (2024-2025) - Rust-based unified tool with 10-100x speed improvements
D) requirements.txt files with manual dependency tracking

Show Answer

Correct Answer: C

The lecture traces three eras: Ancient Times (pip + venv), Middle Ages (Poetry/Pipenv), and Modern Era (uv). The Modern Era is characterized by uv’s revolutionary speed (written in Rust), unified tooling (one tool replaces many), proper dependency resolution, automatic lock files, and smart caching. Options A and B are previous eras, and D is part of the ancient approach.


Question 18: Understanding Named Scripts

When you define road-viewer = "main:main" in the [project.scripts] section, what does the syntax mean?

A) road-viewer is the command name; run the main() function from the main.py module
B) Create a file called road-viewer with main content
C) Run the main.py file twice
D) It’s a comment and has no functional purpose

Show Answer

Correct Answer: A

The syntax command-name = "module:function" creates a CLI command that invokes a specific function. So road-viewer = "main:main" means: when someone runs the road-viewer command, Python will import the main module (main.py) and execute its main() function. This is the professional way to create command-line tools and is used by all major Python CLI applications like pytest, black, and ruff.


Question 19: Global Tools vs. Project Dependencies

What’s the difference between uv tool install ruff and uv add ruff?

A) They do exactly the same thing
B) uv tool install installs globally for system-wide use; uv add adds to the current project’s dependencies
C) uv tool install is deprecated and should never be used
D) uv add is only for libraries, not tools

Show Answer

Correct Answer: B

uv tool install ruff installs the tool globally, making it available everywhere on your system for any project (like installing pytest, black, or other development tools you use across projects). uv add ruff adds it as a dependency of the current project and installs it in that project’s virtual environment. Both have valid use cases: global tools for development utilities, project dependencies for libraries your code imports. They’re not the same (A), neither is deprecated (C), and D is incorrect.


Question 20: The Pedagogical Purpose of This Course

According to the lecture introduction, what’s the main difference between “writing a script that works” and “building professional software”?

A) Professional software uses different programming languages
B) Professional software scales, maintains quality, enables collaboration, and uses proper structure and tooling
C) Professional software is always thousands of lines of code
D) Scripts are for personal use only; professional software is for companies

Show Answer

Correct Answer: B

The lecture’s core message is that professional software engineering isn’t about making code that “just works”—it’s about creating maintainable, scalable, collaborative, properly structured, and well-tooled systems. This includes version control, proper dependencies management, testing, documentation, reproducible environments, and professional workflows. Size alone (C) doesn’t determine professionalism, scripts can be used professionally (D is too narrow), and the same languages are used (A is incorrect).


Scoring Guide


Key Takeaways to Remember

  1. Python’s Dominance - Python leads because of readability, versatility across domains, and the strongest AI/ML ecosystem, not because of execution speed
  2. Virtual Environments - Solve the “dependency hell” problem by isolating project dependencies; they’re stored in .venv/lib/pythonX.X/site-packages/
  3. pyproject.toml - The single source of truth for modern Python projects, containing metadata, dependencies, and build configuration
  4. uv’s Revolution - 10-100x faster than traditional tools because it’s written in Rust with parallel operations and smart caching
  5. Three uv Workflows - Direct run (uv run), manual venv (uv venv + uv sync), and named scripts (most professional)
  6. Modern Commands - Use uv add (not uv pip install) to properly update pyproject.toml and lock files
  7. Named Scripts - Define professional CLI commands in [project.scripts] using the command = "module:function" syntax
  8. Script vs. Production - Production Python adds structure, packaging, documentation, testing, and professional workflows to working code
  9. Package Search Order - Python searches: current directory → venv site-packages → system Python → standard library
  10. Learning Philosophy - Understanding how tools work “under the hood” (like initializing Git yourself) makes you a better developer when using those tools professionally

Remember: The goal isn’t to memorize numbers or specific commands, but to understand the why behind modern Python development practices. When you understand why virtual environments exist, why pyproject.toml is better than requirements.txt, and why uv is faster than pip, you can make informed decisions in real-world development scenarios!

© 2026 Dominik Mueller   •  Powered by Soopr   •  Theme  Moonwalk