Book description
Learn the Python skills and culture you need to become a productive member of any Python project.
About This Book
- Taking a practical approach to studying Python
- A clear appreciation of the sequence-oriented parts of Python
- Emphasis on the way in which Python code is structured
- Learn how to produce bug-free code by using testing tools
Who This Book Is For
The Python Apprentice is for anyone who wants to start building, creating and contributing towards a Python project. No previous knowledge of Python is required, although at least some familiarity with programming in another language is helpful.
What You Will Learn
- Learn the language of Python itself
- Get a start on the Python standard library
- Learn how to integrate 3rd party libraries
- Develop libraries on your own
- Become familiar with the basics of Python testing
In Detail
Experienced programmers want to know how to enhance their craft and we want to help them start as apprentices with Python. We know that before mastering Python you need to learn the culture and the tools to become a productive member of any Python project. Our goal with this book is to give you a practical and thorough introduction to Python programming, providing you with the insight and technical craftsmanship you need to be a productive member of any Python project. Python is a big language, and it's not our intention with this book to cover everything there is to know. We just want to make sure that you, as the developer, know the tools, basic idioms and of course the ins and outs of the language, the standard library and other modules to be able to jump into most projects.
Style and approach
We introduce topics gently and then revisit them on multiple occasions to add the depth required to support your progression as a Python developer. We've worked hard to structure the syllabus to avoid forward references. On only a few occasions do we require you to accept techniques on trust, before explaining them later; where we do, it's to deliberately establish good habits.
Table of contents
- Preface
-
Getting started
- Obtaining and installing Python 3
- Starting Python command line REPL
- Leaving the REPL
- Code structure and significant indentation
- Python culture
- Importing standard library modules
- Getting help()
- Scalar data types: integers, floats, None and bool
- Relational operators
- Control flow: if-statements and while-loops
- Summary
- Strings and Collections
- Modularity
- Built-in types and the object model
-
Exploring Built-in Collection types
- tuple – an immutable sequence of objects
- The tuple constructor
- Strings in action
- Moment of zen
- range – a collection of evenly spaced integers
-
list in action
- Negative indexing for lists (and other sequences)
- Slicing lists
- Copying lists
- Shallow copies
- Repeating lists
- Finding list elements with index()
- Membership testing with count() and in
- Removing list elements by index with del
- Removing list elements by value with remove()
- Inserting into a list
- Concatenating lists
- Rearranging list elements
- Out-of-place rearrangement
- Dictionaries
- set – an unordered collection of unique elements
- Collection protocols
- Summary
-
Exceptions
- Exceptions and control flow
- Handling multiple exceptions
- Programmer errors
- Empty blocks – the pass statement
- Exception objects
- Imprudent return codes
- Re-raising exceptions
- Exceptions are part of your function's API
- Guard clauses
- Exceptions, APIs, and protocols
- Choosing not to guard against TypeError
- Pythonic style – EAFP versus LBYL
- Clean-up actions
- Moment of zen
- Platform-specific code
- Summary
-
Comprehensions, iterables, and generators
- Comprehensions
- Moment of zen
- Iteration protocols
- Generator functions
- Generator expressions
- Batteries included iteration tools
- Pulling it all together
- Summary
-
Defining new types with classes
- Defining classes
- Instance methods
- Instance initializers
- Validation and invariants
- Adding a second class
- Collaborating classes
- Moment of zen
- Booking seats
- Naming methods for implementation details
- Sometimes the only object you need is a function
- Polymorphism and duck-typing
- Inheritance and implementation sharing
- Summary
- Files and Resource Management
- Unit testing with the Python standard library
- Debugging with PDB
- Afterword – Just the Beginning
- Virtual Environments
- Packaging and Distribution
- Installing Third-Party Packages
Product information
- Title: The Python Apprentice
- Author(s):
- Release date: June 2017
- Publisher(s): Packt Publishing
- ISBN: 9781788293181
You might also like
book
The Big Book of Small Python Projects
If you’ve mastered basic Python syntax and you’re ready to start writing programs, you’ll find The …
book
Python Workout
The only way to master a skill is to practice. In Python Workout, author Reuven M. …
book
Beyond the Basic Stuff with Python
You’ve completed a basic Python programming tutorial or finished Al Sweigart’s best selling Automate the Boring …
book
Hypermodern Python Tooling
Keeping up with the Python ecosystem can be daunting. Its developer tooling doesn't provide the out-of-the-box …