Python Assignments — Read. Build. Master.

Grow from fundamentals to production‐ready Python with topic-wise assignments. Each set includes 20 Basic, 20 Intermediate, and 10 Advanced questions so learners can practice deliberately and level up fast.

These ten assignments span the full stack of core Python skills—from basics & control flow through data structures, functions & FP, OOP, exceptions, files & persistence, modules & packages, and advanced concepts/features.

Why practice with these assignments?

  • Move beyond theory—write code, run it, debug it, and compare approaches.
  • Build real-world habits: exception safety, file I/O, package hygiene, and logging/tests.
  • Prepare for interviews with data structures, iterators/generators, comprehensions, and OOP.

How it works

  • Open any assignment and attempt questions in order: Basic → Intermediate → Advanced.
  • Run locally (REPL/IDE), watch outputs & errors, and refactor for clarity.
  • Validate with edge cases; prefer small, pure functions and quick tests.
  • Keep a short “what I learned” note per problem—this compounds fast.

What you’ll achieve

  • A clear mental model of types, control flow, and expressions.
  • Fluency with strings, lists, tuples, sets, dicts, and comprehensions.
  • Confident use of functions, closures, decorators, and FP utilities.
  • Comfortable OOP: classes, inheritance, dunder methods, and composition.
  • Robust exception handling patterns and error hygiene.
  • Practical file handling & persistence (text, binary, CSV, JSON, pickle).
  • Packaging know-how: modules, packages, paths, imports, and venv basics.
  • Iterators/generators, context managers, and memory-savvy patterns.
  • Advanced features: typing hints, logging, unittest, metaprogramming & metaclasses.

Browse the Topics

Use these links to access each assignment and start solving:

  • Python Basics — variables, types, operators, casting, f-strings, identity/membership, bitwise.
  • Control Flow Statements — if/elif/else, loops, break/continue, loop else, patterns with range, enumerate, zip.
  • Data Structures — strings, lists, tuples, sets, dicts, slicing, list/set/dict comprehensions.
  • Functions & Functional Programming — params (/ & *), *args/**kwargs, closures, decorators, map/filter/reduce.
  • Object-Oriented Python — classes, class/static methods, dunder ops, composition vs inheritance, iter/len/getitem.
  • Exception Handling — try/except/else/finally, custom errors, chaining, retry patterns, validation.
  • File Handling & Persistence — open modes, context managers, CSV/JSON/pickle, chunking, tailing, binary I/O.
  • Modules & Packages — stdlib tour, custom modules, packages, relative imports, sys.path, CLI args, venv snapshot.
  • Advanced Python Concepts — iterators, generators, context managers, copying (shallow/deep), comprehension pipelines.
  • Advanced Features — typing, logging, testing with unittest, metaclasses, descriptors, dynamic imports.

Tips for success

  • Prefer small, testable functions; add asserts or quick unittest cases for tricky bits.
  • Use context managers for files; never forget to close handles.
  • Handle errors explicitly; distinguish ValueError/TypeError/IOError and add friendly messages.
  • Reach for comprehensions & generators to keep code concise and memory-efficient.
  • Keep imports tidy; understand your sys.path and package layout.
  • Log useful context (not secrets!) and keep tests green before you optimize.

FAQs

Q1. Which Python version should I use?
Use Python 3.10+ (any modern 3.x works for these tasks). Features like type hints, pattern matching, logging, and modern unittest patterns are demonstrated across the advanced assignments.

Q2. Do I need an IDE or will a REPL do?
Either works. Many learners use VS Code or PyCharm for editing and run snippets in a REPL or terminal for quick feedback. Start simple, then add tooling as you go.

Q3. How do I verify my solutions?
Print intermediate values, add assertions, and write small unit test cases for core functions—especially around edge cases and errors.

Q4. How should I structure files and imports?
Group related functions into modules, expose only what you need from init.py, and keep an eye on sys.path and relative imports. Use a virtual environment for isolation.

Q5. What’s the safest way to work with files?
Always use “with open(…) as f:” to ensure handles close. For large files, read in chunks or stream line by line; for JSON/CSV, handle malformed input gracefully.

Q6. How do I approach exceptions without overusing try/except?
Validate inputs first, catch specific exceptions, and use else/finally for success and cleanup paths. Create custom exceptions only when they clarify intent.

Q7. When should I use a list vs a generator?
Use lists when you need random access or to reuse the data; use generators for streaming or large data to save memory. Practice both in the Advanced Concepts set.

Q8. Are OOP patterns required, or can I stay functional?
You’ll practice both. Use functions, closures, and decorators for behavior reuse; reach for classes when modeling stateful objects or leveraging dunder protocols.

Q9. Do I need third-party libraries?
No. Everything here uses the standard library—json, csv, pickle, logging, unittest, etc.—so you can learn fundamentals first.

Q10. What’s a good progression if I’m completely new?
Go in order: Basics → Control Flow → Data Structures → Functions/Functional Programming → OOP → Exceptions → Files → Modules/Packages → Advanced Concepts → Advanced Features. Each builds on the last with hands-on practice.