Learn Python Programming: An in-depth introduction to the fundamentals of Python, 3rd Edition
- Length: 506 pages
- Edition: 3
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2021-11-09
- ISBN-10: 1801815097
- ISBN-13: 9781801815093
- Sales Rank: #230802 (See Top 100 Books)
Get up and running with Python through concise tutorials and practical projects in this fully updated edition
Key Features
- Discover how to think like a Python programmer
- Extensively revised with richer examples, Python 3.9 syntax, and new chapters on APIs and packaging and distributing Python code
- Learn the fundamentals of Python through real-world projects in API development, GUI programming, and data science
Book Description
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, packaging 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-world Python projects based on the concepts you have learned.
What you will learn
- Get Python up and running on Windows, Mac, and Linux
- Write elegant, reusable, and efficient code in any situation
- Avoid common pitfalls like duplication, complicated design, and over-engineering
- Understand when to use the functional or object-oriented approach to programming
- Build a simple API with FastAPI and program GUI applications with Tkinter
- Get an initial overview of more complex topics such as data persistence and cryptography
- Fetch, clean, and manipulate data, making efficient use of Python’s built-in data structures
Who This Book Is For
This book is for anyone who has some programming experience, but not necessarily with Python. Some knowledge of basic programming concepts will come in handy, although it is not a requirement.
Table of Contents
- A gentle introduction to Python
- Built-in Data Types
- Conditionals and Iteration
- Functions, the building blocks of code
- Comprehensions and Generators
- OOP, Decorators, and Iterators
- Exceptions and Context Managers
- Files and Data Persistence
- Cryptography and Tokens
- Testing
- Debugging and Profiling
- GUIs and Scripting
- Data Science in brief
- Introduction to API Development
- Packaging Python Applications
Preface Who this book is for What this book covers To get the most out of this book Get in touch A Gentle Introduction to Python A proper introduction Enter the Python About Python Portability Coherence Developer productivity An extensive library Software quality Software integration Satisfaction and enjoyment What are the drawbacks? Who is using Python today? Setting up the environment Python 2 versus Python 3 Installing Python Setting up the Python interpreter About virtual environments Your first virtual environment Installing third-party libraries Your friend, the console How to run a Python program Running Python scripts Running the Python interactive shell Running Python as a service Running Python as a GUI application How is Python code organized? How do we use modules and packages? Python's execution model Names and namespaces Scopes Objects and classes Guidelines for writing good code Python culture A note on IDEs Summary Built-In Data Types Everything is an object Mutable or immutable? That is the question Numbers Integers Booleans Real numbers Complex numbers Fractions and decimals Immutable sequences Strings and bytes Encoding and decoding strings Indexing and slicing strings String formatting Tuples Mutable sequences Lists Bytearrays Set types Mapping types: dictionaries Data types Dates and times The standard library Third-party libraries The collections module namedtuple defaultdict ChainMap Enums Final considerations Small value caching How to choose data structures About indexing and slicing About names Summary Conditionals and Iteration Conditional programming A specialized else: elif The ternary operator Looping The for loop Iterating over a range Iterating over a sequence Iterators and iterables Iterating over multiple sequences The while loop The break and continue statements A special else clause Assignment expressions Statements and expressions Using the walrus operator A word of warning Putting all this together A prime generator Applying discounts A quick peek at the itertools module Infinite iterators Iterators terminating on the shortest input sequence Combinatoric generators Summary Functions, the Building Blocks of Code Why use functions? Reducing code duplication Splitting a complex task Hiding implementation details Improving readability Improving traceability Scopes and name resolution The global and nonlocal statements Input parameters Argument-passing Assignment to parameter names Changing a mutable object Passing arguments Positional arguments Keyword arguments Iterable unpacking Dictionary unpacking Combining argument types Defining parameters Optional parameters Variable positional parameters Variable keyword parameters Positional-only parameters Keyword-only parameters Combining input parameters More signature examples Avoid the trap! Mutable defaults Return values Returning multiple values A few useful tips Recursive functions Anonymous functions Function attributes Built-in functions Documenting your code Importing objects Relative imports One final example Summary Comprehensions and Generators The map, zip, and filter functions map zip filter Comprehensions Nested comprehensions Filtering a comprehension Dictionary comprehensions Set comprehensions Generators Generator functions Going beyond next The yield from expression Generator expressions Some performance considerations Don't overdo comprehensions and generators Name localization Generation behavior in built-ins One last example Summary OOP, Decorators, and Iterators Decorators A decorator factory Object-oriented programming (OOP) The simplest Python class Class and object namespaces Attribute shadowing The self argument Initializing an instance OOP is about code reuse Inheritance and composition Accessing a base class Multiple inheritance Method resolution order Class and static methods Static methods Class methods Private methods and name mangling The property decorator The cached_property decorator Operator overloading Polymorphism – a brief overview Data classes Writing a custom iterator Summary Exceptions and Context Managers Exceptions Raising exceptions Defining your own exceptions Tracebacks Handling exceptions Not only for errors Context managers Class-based context managers Generator-based context managers Summary Files and Data Persistence Working with files and directories Opening files Using a context manager to open a file Reading and writing to a file Reading and writing in binary mode Protecting against overwriting an existing file Checking for file and directory existence Manipulating files and directories Manipulating pathnames Temporary files and directories Directory content File and directory compression Data interchange formats Working with JSON Custom encoding/decoding with JSON I/O, streams, and requests Using an in-memory stream Making HTTP requests Persisting data on disk Serializing data with pickle Saving data with shelve Saving data to a database Summary Cryptography and Tokens The need for cryptography Useful guidelines Hashlib HMAC Secrets Random numbers Token generation Digest comparison JSON Web Tokens Registered claims Time-related claims Authentication-related claims Using asymmetric (public key) algorithms Useful references Summary Testing Testing your application The anatomy of a test Testing guidelines Unit testing Writing a unit test Mock objects and patching Assertions Testing a CSV generator Boundaries and granularity Testing the export function Final considerations Test-driven development Summary Debugging and Profiling Debugging techniques Debugging with print Debugging with a custom function Using the Python debugger Inspecting logs Other techniques Reading tracebacks Assertions Where to find information Troubleshooting guidelines Where to inspect Using tests to debug Monitoring Profiling Python When to profile Measuring execution time Summary GUIs and Scripting First approach: scripting The imports Parsing arguments The business logic Second approach: a GUI application The imports The layout logic The business logic Fetching the web page Saving the images Alerting the user How can we improve the application? Where do we go from here? The turtle module wxPython, Kivy, and PyQt The principle of least astonishment Threading considerations Summary Data Science in Brief IPython and Jupyter Notebook Using Anaconda Starting a Notebook Dealing with data Setting up the Notebook Preparing the data Cleaning the data Creating the DataFrame Unpacking the campaign name Unpacking the user data Cleaning everything up Saving the DataFrame to a file Visualizing the results Where do we go from here? Summary Introduction to API Development What is the Web? How does the Web work? Response status codes Type hinting: An overview Why type hinting? Type hinting in a nutshell APIs: An introduction What is an API? What is the purpose of an API? API protocols API data-exchange formats The railway API Modeling the database Main setup and configuration Adding settings Station endpoints Reading data Creating data Updating data Deleting data User authentication Documenting the API Consuming an API Calling the API from Django Where do we go from here? Summary Packaging Python Applications The Python Package Index The train schedule project Packaging with setuptools Required files pyproject.toml License README Changelog setup.cfg setup.py MANIFEST.in Package metadata Accessing metadata in your code Defining the package contents Accessing package data files Specifying dependencies Entry points Building and publishing packages Building Publishing Advice for starting new projects Alternative tools Further reading Summary Other Books You May Enjoy Index
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Learn Python Programming: An in-depth introduction to the fundamentals of Python, 3rd Edition
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.