Python Essentials

Modernize existing Python code and plan code migrations to Python using this definitive guide

Python Essentials

Steven F. Lott

1 customer reviews
Modernize existing Python code and plan code migrations to Python using this definitive guide
Mapt Subscription
FREE
$29.99/m after trial
eBook
$22.40
RRP $31.99
Save 29%
Print + eBook
$39.99
RRP $39.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$22.40
$39.99
$29.99p/m after trial
RRP $31.99
RRP $39.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781784390341
Paperback298 pages

Book Description

Python Essentials provides a vital tour of the most critical features of Python. Starting with setup and installation, you will soon dive into exploring built-in-library types, Python's rich collection of operators and built-in functions, variables, assignment and scoping rules.

From this foundation, you will explore functions, a crucial aspect of any programming language, including considerable sophistication in defining parameters to a function and providing argument values. Explore advanced functional programming using generator expressions, comprehensions, and generator functions. Handle file input and output using web services and context managers, exception handling and explore wider, popular frameworks.

Through this concise and practical guide, you will explore all you need to know to leverage this powerful, and industry-standard, programming language.

Table of Contents

Chapter 1: Getting Started
Installation or upgrade
Using the Read-Evaluate-Print Loop (REPL)
Interacting with the help subsystem
Creating simple script files
The Python ecosystem
Looking at other Python interpreters
Summary
Chapter 2: Simple Data Types
Introducing the built-in operators
The numeric tower
The math libraries
Using bits and Boolean values
Working with sequences
Using string and bytes values
Using the tuple collection
The None object
The consequences of immutability
Using the built-in conversion functions
Summary
Chapter 3: Expressions and Output
Expressions, operators, and data types
The print() function
Examining syntax rules
Splitting, partitioning, and joining strings
Summary of the standard string libraries
Summary
Chapter 4: Variables, Assignment and Scoping Rules
Simple assignment and variables
Multiple assignment
Using the head, *tail assignment
Augmented assignment
The input() function
Python language concepts
The Python namespace concept
Summary
Chapter 5: Logic, Comparisons, and Conditions
Boolean data and the bool() function
Comparison operators
Logic operators – and, or, not, if-else
The if-elif-else statement
The pass statement as a placeholder
The assert statement
The logic of the None object
Summary
Chapter 6: More Complex Data Types
The mutability and immutability distinction
Using the list collection
Using collection functions
Using the set collection
Mappings
Processing collections with the for statement
Iterating with the while statement
The continue and break statements
Using the else clause on a loop
Summary
Chapter 7: Basic Function Definitions
Looking at the five kinds of callables
Defining functions with positional parameters
Mutable and immutable argument values
Defining optional parameters via default values
Using the "everything else" notations of * and **
Nested function definitions
Working with namespaces
Defining lambdas
Writing additional function annotations
Summary
Chapter 8: More Advanced Functions
Using the for statement with iterable collections
Consequences and next steps
Using generator expressions and comprehensions
Defining generator functions with the yield statement
Using the higher-order functions
Using the built-in reductions – max, min, and reduce
Three ways to sort a sequence
Functional programming design patterns
Summary
Chapter 9: Exceptions
The core exception concept
Using the try and except statements
Matching exception classes in an except clause
Creating our own exceptions
Using a finally clause
Use cases for exceptions
Issuing warnings instead of exceptions
Permission versus forgiveness – a Pythonic approach
Summary
Chapter 10: Files, Databases, Networks, and Contexts
The essential file concept
Using a context manager via the with statement
Using the shelve module as a database
Web services and Internet protocols
Physical format considerations
Summary
Chapter 11: Class Definitions
Creating a class
Writing the suite of statements in a class
Using instance variables and methods
Pythonic object-oriented programming
Using properties
Using inheritance to simplify class definitions
Using class methods and attributes
Using __slots__ to save storage
The ABCs of abstract base classes
Summary
Chapter 12: Scripts, Modules, Packages, Libraries, and Applications
Script file rules
Running a script by the filename
Creating a reusable module
Creating a hybrid library/application module
Creating a package
Designing alternative implementations
Seeing the package search path
Summary
Chapter 13: Metaprogramming and Decorators
Simple metaprogramming with decorators
Defining our own decorator
More complex metaprogramming with metaclasses
Summary
Chapter 14: Fit and Finish – Unit Testing, Packaging, and Documentation
Writing docstrings
Writing unit tests with doctest
Using the unittest library for testing
Using other add-on test libraries
Logging events and conditions
Writing documentation with RST markup
Organizing Python code
Summary
Chapter 15: Next Steps
Leveraging the standard library
Leveraging PyPI – the Python Package Index
Types of applications
Building CLI applications
Building GUI applications
Building web applications
Plugging into a MapReduce framework
Summary

What You Will Learn

  • Use Python interactively and master the art of writing efficient Python scripts
  • Learn techniques for working with string data, including how to use regular expressions to parse strings
  • Get to know how the short-circuit and if-else logic operators work
  • Explore mutable data structures including list, set, and dict
  • Define functions with positional and optional parameters, and learn to use keyword argument values when calling a function
  • Write generator functions, generator expressions, and comprehensions
  • Master the use of exceptions for handling errors and other unexpected conditions
  • Understand the importance of working with files, context manager, and the with statement

Authors

Table of Contents

Chapter 1: Getting Started
Installation or upgrade
Using the Read-Evaluate-Print Loop (REPL)
Interacting with the help subsystem
Creating simple script files
The Python ecosystem
Looking at other Python interpreters
Summary
Chapter 2: Simple Data Types
Introducing the built-in operators
The numeric tower
The math libraries
Using bits and Boolean values
Working with sequences
Using string and bytes values
Using the tuple collection
The None object
The consequences of immutability
Using the built-in conversion functions
Summary
Chapter 3: Expressions and Output
Expressions, operators, and data types
The print() function
Examining syntax rules
Splitting, partitioning, and joining strings
Summary of the standard string libraries
Summary
Chapter 4: Variables, Assignment and Scoping Rules
Simple assignment and variables
Multiple assignment
Using the head, *tail assignment
Augmented assignment
The input() function
Python language concepts
The Python namespace concept
Summary
Chapter 5: Logic, Comparisons, and Conditions
Boolean data and the bool() function
Comparison operators
Logic operators – and, or, not, if-else
The if-elif-else statement
The pass statement as a placeholder
The assert statement
The logic of the None object
Summary
Chapter 6: More Complex Data Types
The mutability and immutability distinction
Using the list collection
Using collection functions
Using the set collection
Mappings
Processing collections with the for statement
Iterating with the while statement
The continue and break statements
Using the else clause on a loop
Summary
Chapter 7: Basic Function Definitions
Looking at the five kinds of callables
Defining functions with positional parameters
Mutable and immutable argument values
Defining optional parameters via default values
Using the "everything else" notations of * and **
Nested function definitions
Working with namespaces
Defining lambdas
Writing additional function annotations
Summary
Chapter 8: More Advanced Functions
Using the for statement with iterable collections
Consequences and next steps
Using generator expressions and comprehensions
Defining generator functions with the yield statement
Using the higher-order functions
Using the built-in reductions – max, min, and reduce
Three ways to sort a sequence
Functional programming design patterns
Summary
Chapter 9: Exceptions
The core exception concept
Using the try and except statements
Matching exception classes in an except clause
Creating our own exceptions
Using a finally clause
Use cases for exceptions
Issuing warnings instead of exceptions
Permission versus forgiveness – a Pythonic approach
Summary
Chapter 10: Files, Databases, Networks, and Contexts
The essential file concept
Using a context manager via the with statement
Using the shelve module as a database
Web services and Internet protocols
Physical format considerations
Summary
Chapter 11: Class Definitions
Creating a class
Writing the suite of statements in a class
Using instance variables and methods
Pythonic object-oriented programming
Using properties
Using inheritance to simplify class definitions
Using class methods and attributes
Using __slots__ to save storage
The ABCs of abstract base classes
Summary
Chapter 12: Scripts, Modules, Packages, Libraries, and Applications
Script file rules
Running a script by the filename
Creating a reusable module
Creating a hybrid library/application module
Creating a package
Designing alternative implementations
Seeing the package search path
Summary
Chapter 13: Metaprogramming and Decorators
Simple metaprogramming with decorators
Defining our own decorator
More complex metaprogramming with metaclasses
Summary
Chapter 14: Fit and Finish – Unit Testing, Packaging, and Documentation
Writing docstrings
Writing unit tests with doctest
Using the unittest library for testing
Using other add-on test libraries
Logging events and conditions
Writing documentation with RST markup
Organizing Python code
Summary
Chapter 15: Next Steps
Leveraging the standard library
Leveraging PyPI – the Python Package Index
Types of applications
Building CLI applications
Building GUI applications
Building web applications
Plugging into a MapReduce framework
Summary

Book Details

ISBN 139781784390341
Paperback298 pages
Read More
From 1 reviews

Read More Reviews

Recommended for You

Functional Python Programming Book Cover
Functional Python Programming
$ 29.99
$ 21.00
Mastering Object-oriented Python Book Cover
Mastering Object-oriented Python
$ 26.99
$ 18.90
Python Data Analysis Book Cover
Python Data Analysis
$ 29.99
$ 21.00
Python Machine Learning Book Cover
Python Machine Learning
$ 35.99
$ 25.20
Functional Python Programming Book Cover
Functional Python Programming
$ 29.99
$ 21.00
Python GUI Programming Cookbook Book Cover
Python GUI Programming Cookbook
$ 35.99
$ 25.20