Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Heinrich Kruger, Fabrizio Romano

Rating 4.0 AI initial rating

Learn Python Programming, Third Edition is both a theoretical and practical introduction to Python, an extremely flexible and powerful programming language that can be applied to many disciplines. This book will make learning Python easy and give you a thorough understanding of the language. You'll learn how to write programs, build modern APIs, and work with data by using renowned Python data science libraries. This revised edition covers the latest updates on API management, packing applications, and testing. There is also broader coverage of context managers and an updated data science chapter. The book empowers you to take ownership of writing your software and become independent in fetching the resources you need. You will have a clear idea of where to go and how to build on what you have learned from the book. Through examples, the book explores a wide range of applications and concludes by building real-workd Python projects based on the concepts you have learned.

AI Reading Assistant

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

AI guide
【One-Line Pitch】 A patient, example-driven tour of Python that takes you from setting up a virtual environment to writing idiomatic code with generators, decorators, context managers, and real-world projects—best suited to motivated beginners and self-taught developers who want depth rather than a quick syntax cheat sheet. 【Book Arc】 - **Opening (~0%–10%)**: Orients you to what programming is for—naming objects, reacting to input, controlling flow—then walks through installing Python and creating an isolated virtual environment on Windows and Linux, so your first programs run in a clean, reproducible setup. - **Early (~10%–32%)**: Builds the language floor: built-in data types (numbers, strings, collections, dates and times), conditionals and iteration (including the walrus operator and a peek at `itertools`), and functions as the unit of reuse, with scopes, argument passing, and the `global`/`nonlocal` statements. - **Middle (~32%–55%)**: Moves into Python's expressive core—comprehensions and generators for concise, memory-frugal code; object-oriented programming with classes, magic methods, and decorators; and exceptions with context managers for handling errors and resources safely. - **Late (~55%–80%)**: Shifts from language mechanics to engineering practice: files and data persistence, testing, packaging applications, and building and managing modern APIs—the areas the third edition explicitly revised. - **Ending (~80%–100%)**: Consolidates everything through a data science chapter using well-known Python libraries and capstone-style real-world projects, pointing you toward where to go next. (Excerpts do not cover the specific project titles or data science library walkthroughs in detail.) 【Key Takeaways】 - **Objects, names, and mutability are the mental model** (Early): Python binds names to objects; whether an object is mutable or immutable explains much of the language's surprising behavior, so grasp this before memorizing syntax. - **Small idioms carry real weight** (Early): Floor division rounds toward negative infinity while `int()` truncates toward zero; `pow()` and `**` differ in return type; `==` compares value while `is` compares identity—details that trip up newcomers and reward careful reading. - **Functions are the primary defense against duplication** (Middle): The book argues reuse through concrete failure modes—bugs copied across the codebase, missed fixes, inconsistent behavior—making functions a quality practice, not just a convenience. - **Comprehensions and generators buy conciseness and memory savings** (Middle): Treat this as the bridge from "writing code that works" to "writing code that scales," especially when data grows beyond what fits comfortably in memory. - **OOP is taught through namespaces and magic methods** (Middle): Classes are explained as namespaces reached via the dot operator, with `__init__` as initializer and dunder names reserved for Python—practical grounding before decorators build on it. - **Errors and resources deserve first-class treatment** (Middle): Exceptions and context managers are paired deliberately; the third edition broadens context-manager coverage, reflecting how much real code depends on safe resource handling. - **The book extends past syntax into shipping software** (Late): Testing, packaging, and API management are treated as part of learning Python, which is what separates this from pure language primers. - **Independence is the stated end goal** (Ending): The authors aim for readers who can fetch their own resources and decide what to learn next, with capstone projects as the proof of concept. 【Reading Tips】 - **Deep-read Chapters 1–4 even if you've dabbled**: the virtual-environment setup, mutability model, and function scoping are where self-taught gaps usually hide; skimming here costs you later. - **Skim the data-type chapter selectively**: use it as a reference for collections and `datetime` rather than reading linearly—the five-ways-to-build-a-dict style examples are illustrative, not mandatory memorization. - **Slow down at generators, decorators, and context managers**: these are the conceptual peaks; work the examples by hand rather than reading them passively. - **Treat the late chapters as a project track**: do the testing, packaging, and API material with your own small project so the capstone chapters have something to attach to. - **Keep the official docs open alongside**: the book itself defers to documentation for exhaustive formatting and library details, so build that habit early. 【Coverage Limits】 This guide is based on stratified excerpts covering the front matter, table of contents, and early-to-middle chapters; the late API, packaging, testing, data science, and project chapters are described only at the level the preface and blurb allow, so specifics there are not verified.
Page 10
input sequence 112 Combinatoric generators 113 Summary 113 Chapter 4: Functions, the Building Blocks of Code 115 Why use functions? 116 Reducing code duplica...
View in text
Excerpt 2
do this effectively, we need to have a construct that will hold the code for us so that we can call that construct every time we need to repeat the logic ins...
View in text
Excerpt 3
type(diff) <class 'datetime.timedelta'> >>> diff.days 2109 >>> diff.total_seconds() 182223650.0 >>> today + timedelta(days=49) datetime.date(2021, 5, 16) >>>...
View in text
Excerpt 4
timedelta(days=1) # today + 1 day is tomorrow products = [ {'sku': '1', 'expiration_date': today, 'price': 100.0}, {'sku': '2', 'expiration_date': tomorrow,...
View in text
Excerpt 5
N is either 0 or 1—the function returns 1 with no need for further calculation. On the other hand, in the general case, N! returns the product: 1 * 2 * ... *...
View in text
Excerpt 6
you. Now, the fibonacci() function is a generator function. First, we yield 0, and then, if N is 0, we return (this will cause a StopIteration exception to b...
View in text
Excerpt 7
on them. Exceptions can be used for more than just errors: # exceptions/for.loop.py n = 100 found = False for a in range(n): if found: break for b in range(n...
View in text
Excerpt 8
why this example is slightly more complex lies in the fact that datetime objects in Python can be time zone-aware or not; therefore, we need to be more caref...
View in text
Tags
AI categories
Programming LanguagePythonSoftware
Publisher: Packt Publishing
Publish Year: 2021
Language: English
File Format: PDF
File Size: 7.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…