Preface

Python is the preferred choice of developers, engineers, data scientists, and hobbyists everywhere. It is a great scripting language that can power your applications and provide great speed, safety, and scalability. By exposing Python as a series of simple recipes, you can gain insights into specific language features in a particular context. Having a tangible context helps make the language or standard library feature easier to understand.

This book takes a recipe-based approach, where each recipe addresses specific problems and issues.

What you need for this book

All you need to follow through the examples in this book is a computer running any Python 3.8.5 or newer. Some of the examples can be adapted to work with Python 3 versions prior to 3.8. A number of examples are specific to Python 3.8 features.

It's often easiest to install a fresh copy of Python. This can be downloaded from https://www.python.org/downloads/. An alternative is to start with Miniconda (https://docs.conda.io/en/latest/miniconda.html) and use the conda tool to create a Python 3.8 (or newer) environment.

Python 2 cannot easily be used any more. Some Linux distributions and older macOS releases included a version of Python 2. It should be thought of as part of the operating system, and not a general software development tool.

Who this book is for

The book is for web developers, programmers, enterprise programmers, engineers, and big data scientists. If you are a beginner also, this book will get you started. If you are experienced, it will expand your knowledge base. A basic knowledge of programming would help.

What this book covers

Chapter 1, Numbers, Strings, and Tuples, will look at the different kinds of numbers, work with strings, use tuples, and use the essential built-in types in Python. We will also exploit the full power of the unicode character set.

Chapter 2, Statements and Syntax, will cover some basics of creating script files first. Then we'll move on to looking at some of the complex statements, including if, while, for, try, with, and raise.

Chapter 3, Function Definitions, will look at a number of function definition techniques. We'll also look at the Python 3.5 typing module and see how we can create more formal annotations for our functions.

Chapter 4, Built-In Data Structures Part 1 – Lists and Sets, will look at an overview of the various structures that are available and what problems they solve. From there, we can look at lists and sets in detail.

Chapter 5, Built-In Data Structures Part 2 – Dictionaries, will continue examining the built-in data structures, looking at dictionaries in detail. This chapter will also look at some more advanced topics related to how Python handles references to objects.

Chapter 6, User Inputs and Outputs, will explain how to use the different features of the print() function. We'll also look at the different functions used to provide user input.

Chapter 7, Basics of Classes and Objects, will create classes that implement a number of statistical formulae.

Chapter 8, More Advanced Class Design, will dive a little more deeply into Python classes. We will combine some features we have previously learned about to create more sophisticated objects.

Chapter 9, Functional Programming Features, will examine ways Python can be used for functional programming. This will emphasize function definitions and stateless, immutable objects.

Chapter 10, Input/Output, Physical Format, and Logical Layout, will work with different file formats such as JSON, XML, and HTML.

Chapter 11, Testing, will give us a detailed description of the different testing frameworks used in Python.

Chapter 12, Web Services, will look at a number of recipes for creating RESTful web services and also serving static or dynamic content.

Chapter 13, Application Integration: Configuration, will start looking at ways that we can design applications that can be composed to create larger, more sophisticated composite applications.

Chapter 14, Application Integration: Combination, will look at ways that complications that can arise from composite applications and the need to centralize some features, such as command-line parsing.

Chapter 15, Statistical Programming and Linear Regression, will look at some basic statistical calculations that we can do with Python's built-in libraries and data structures. We'll look at the questions of correlation, randomness, and the null hypothesis.

To get the most out of this book

To get the most out of this book you can download the example code files and the color images as per the instructions below.

Download the example code files

You can download the example code files for this book from your account at packtpub.com. If you purchased this book elsewhere, you can visit packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the on-screen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Modern-Python-Cookbook-Second-Edition. This repository is also the best places to start a conversation about specific topics discussed in the book. Feel free to open an issue if you want to engage with the authors or other readers. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

    if distance is None:
        distance = rate * time
    elif rate is None:
        rate = distance / time
    elif time is None:
        time = distance / rate

Any command-line input or output is written as follows:

>>> import math
>>> math.factorial(52)
80658175170943878571660636856403766975289505440883277824000000000000
New terms and important words are shown in bold.

Warnings or important notes appear like this.

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected], and mention the book's title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book we would be grateful if you would report this to us. Please visit, packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset