Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Reuven M. Lerner

Rating No ratings yet

Python Workout presents 50 exercises designed to deepen the reader's skill with Python. Readers will not only tackle exercises using built-in data structures, but also more advanced techniques, such as functional programming, object-oriented programming, iterators, and generators. With each engaging challenge, readers will practice a new skill and learn how to apply it to everyday coding tasks.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 Python Workout is a hands-on exercise book that builds real Python fluency through 50 short, focused challenges—perfect for programmers who already know the basics but want to solidify their skills through deliberate practice rather than passive reading. 【Book Arc】 - **Opening (~0%–10%)**: Introduces the book's exercise-centric philosophy and starts with numeric types, covering basic operations, random number generation, and user input handling through simple games and calculations. - **Early (~10%–30%)**: Moves into strings, teaching immutability, Unicode handling, iteration, and text manipulation through exercises like Pig Latin and Ubbi Dubbi translations. - **Early–Middle (~30%–50%)**: Covers lists and tuples, emphasizing sequence operations, sorting with custom keys, list comprehensions, and the practical differences between mutable and immutable data structures. - **Middle (~50%–70%)**: Advances into files, functions, and functional programming with comprehensions, exploring splat operators, lambda functions, and the operator module for cleaner code. - **Late (~70%–90%)**: Introduces modules, packages, objects, and object-oriented programming, building on earlier concepts to create more structured and reusable code. - **Ending (~90%–100%)**: Finishes with iterators and generators, showing how to work with lazy evaluation and memory-efficient data processing. 【Key Takeaways】 - **Exercise-first learning works** (Opening): The book's core premise is that you learn Python best by solving problems, not just reading explanations—each exercise is designed to be completed in about ten minutes. - **Numeric types require careful handling** (Early): Understanding integer vs. float behavior, random number generation, and type conversion (like int('5')) is foundational; the book highlights that Python 3 prevents cross-type comparisons that were allowed in Python 2. - **Strings are immutable sequences** (Early): Python strings can't be changed in place, contain Unicode characters, and support iteration and indexing; the book emphasizes building new strings efficiently rather than modifying existing ones. - **Lists vs. tuples is a design decision** (Middle): Both are sequences, but lists are mutable while tuples are immutable—choosing the right one affects performance and code clarity; the book provides a comparison table to guide decisions. - **The splat operator (*) enables flexible functions** (Middle): Using *args lets functions accept any number of arguments, which are collected into a tuple; this pattern appears repeatedly and is essential for writing versatile code. - **Sorting with keys is powerful** (Middle): The key parameter to sorted() allows custom sorting logic, and lambda functions or operator.itemgetter provide clean ways to sort complex data structures like lists of dictionaries. - **String formatting controls output precision** (Middle): Format specifiers like {2:5.2f} give precise control over alignment, decimal places, and padding—critical for producing professional-looking output. - **Building strings via lists is more efficient** (Early): Appending to a list and then joining is better than repeated string concatenation, especially for large loops, because strings are immutable and each concatenation creates a new object. 【Reading Tips】 - **Do the exercises before reading solutions**: The book's value comes from attempting each challenge first; solutions are provided but should be used as a check, not a crutch. - **Skim the "Beyond the exercise" sections**: These extensions offer valuable variations and deeper explorations—they're worth reading even if you don't complete them all. - **Pay attention to the "Working it out" explanations**: These walkthroughs reveal the author's problem-solving process, which is often more instructive than the final code. - **Use the Python Tutor links**: The book references visual execution tools that help clarify how code flows, especially for loops and function calls. - **Focus on the "TIP" and "NOTE" callouts**: These highlight common pitfalls and best practices (like f-strings and the inclusive nature of random.randint) that are easy to miss. 【Coverage Limits】 The excerpts primarily cover the first half of the book (numeric types through lists/tuples); later chapters on files, functions, comprehensions, modules, objects, iterators, and generators are mentioned in the table of contents but not detailed in the provided material.
Page 18
iels, Christoffer Fink, David Krief, David Moravec, David R. Snyder, Gary Hubbard, Geoff Craig, Glen Sirakavit, Jean-François Morin, Jeff Smith, Jens Christi...
View in text
Excerpt 2
a tuple. It’ll be an empty tuple, but a tuple nonetheless. The splat operator is especially useful when you want to receive an unknown num- ber of arguments....
View in text
Excerpt 3
s short video walkthrough of the solution: https://livebook.manning.com/ video/python-workout. Beyond the exercise It’s common to want to replace one value w...
View in text
Excerpt 4
erator module has the itemgetter function. itemgetter takes any number of arguments and returns a function that applies each of those argu- ments in square b...
View in text
Excerpt 5
tions (http://mng.bz/6Qwy) module that allows you to define a dict that works just like a regular one—until you ask it for a key that doesn’t exist. In such...
View in text
Excerpt 6
reate a dict in which the keys are the usernames (as in the main exercise) and the values are themselves dicts with keys (and appropriate values) for user ID...
View in text
Excerpt 7
! hello('a', 'b') Error: Too many arguments No return value NOTE Parameters with defaults must come after those without defaults. WARNING Never use a mutable...
View in text
Excerpt 8
d(10)) print(symbol_password(5)) print(symbol_password(10)) You can work through a version of this code in the Python Tutor at http://mng.bz/ GVEM. Screencas...
View in text
Tags
AI categories
Programming LanguagePythonCode
ISBN: 1617295507
Publish Year: 2020
Language: English
Pages: 249
File Format: PDF
File Size: 9.2 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…