Python Essentials For Dummies 2024934008, 9781394263479, 9781394263486, 9781394263493

The no-nonsense way to get started coding in the Python programming language Python Essentials For Dummies is a quick r

137 115 2MB

English Pages 192 Year 2024

Report DMCA / Copyright

DOWNLOAD EPUB FILE

Table of contents :
Cover

Title Page

Copyright

Introduction

About This Book

Foolish Assumptions

Icons Used in This Book

Where to Go from Here

Chapter 1: Starting with Python

Why Python Is Hot

Choosing the Right Python

Tools for Success

Chapter 2: Using Interactive Mode, Getting Help, and Writing Apps

Using Python’s Interactive Mode

Creating a Folder for Your Python Code

Typing, Editing, and Debugging Python Code

Chapter 3: Python Elements and Syntax

The Zen of Python

Introducing Object-Oriented Programming

Discovering Why Indentations Count, Big Time

Using Python Modules

Chapter 4: Building Your First Python Application

Opening the Python App File

Typing and Using Python Comments

Understanding Python Data Types

Working with Python Operators

Creating and Using Variables

Understanding What Syntax Is and Why It Matters

Chapter 5: Working with Numbers, Text, and Dates

Calculating Numbers with Functions

Still More Math Functions

Formatting Numbers

Grappling with Weirder Numbers

Manipulating Strings

Uncovering Dates and Times

Chapter 6: Controlling the Action

Main Operators for Controlling the Action

Making Decisions with if

Repeating a Process with for

Looping with while

Chapter 7: Speeding Along with Lists and Tuples

Defining and Using Lists

What’s a Tuple and Who Cares?

Working with Sets

Chapter 8: Wrangling Bigger Chunks of Code

Creating a Function

Commenting a Function

Passing Information to a Function

Returning Values from Functions

Chapter 9: Sidestepping Errors

Understanding Exceptions

Handling Errors Gracefully

Being Specific about Exceptions

Keeping Your App from Crashing

Adding an else to the Mix

Using try … except … else … finally

Raising Your Own Exceptions

Chapter 10: Working with External Files

Understanding Text and Binary Files

Opening and Closing Files

Reading a File’s Contents

Looping through a File

Reading and Copying a Binary File

Chapter 11: Juggling JSON Data

Organizing JSON Data

Understanding Serialization

Loading Data from JSON Files

Dumping Python Data to JSON

Chapter 12: Interacting with the Internet

Seeing How the Web Works

Chapter 13: Libraries, Packages, and Modules

Understanding the Python Standard Library

Exploring Python Packages

Importing Python Modules

Chapter 14: The Ten Most Essential Aspects of Python

Being Pythonic

Identifying the Importance of Indents

Understanding Python Syntax

Appreciating the Flexibility of Python Variables

Seeing Lists as Your Friend

Controlling Your Program

Understanding Python Functions

Figuring Out Errors

Using Other People’s Modules

Using the Web and AI When You Have Problems

Index

About the Authors

Connect with Dummies

End User License Agreement

List of Tables

Chapter 4

TABLE 4-1 Python’s Arithmetic Operators

TABLE 4-2 Python Comparison Operators

TABLE 4-3 Python Boolean Operators

Chapter 5

TABLE 5-1 Some Built-In Python Functions for Numbers

TABLE 5-2 Some Functions from the Python Math Module

TABLE 5-3 Python for Base 2, 8, and 16 Numbers

TABLE 5-4 Python Sequence Operators That Work with Strings

TABLE 5-5 Built-In Methods for Python 3 Strings

TABLE 5-6 Sample Date Format Strings

TABLE 5-7 Sample Datetime Format Strings

Chapter 6

TABLE 6-1 Python Comparison Operators for Decision-Making

TABLE 6-2 Python Logical Operators

Chapter 7

TABLE 7-1 Methods for Working with Lists

Chapter 11

TABLE 11-1 Python JSON Methods for Serializing and Deserializing JSON Data

TABLE 11-2 Python and JSON Data Conversions

Chapter 12

TABLE 12-1 Common HTTP Status Codes

TABLE 12-2 Packages from the Python urllib Library

List of Illustrations

Chapter 1

FIGURE 1-1: Obtaining the Python extension in VS Code.

FIGURE 1-2: The GitHub Copilot extension in VS Code.

FIGURE 1-3: The Accounts and Copilot icons in VS Code.

Chapter 2

FIGURE 2-1: The Terminal pane in VS Code.

FIGURE 2-2: Python doesn’t know what howdy means.

FIGURE 2-3: Keyword help.

FIGURE 2-4: The hello.py file contains some Python code and has unsaved changes...

FIGURE 2-5: Output from

FIGURE 2-6: PRINT is typed incorrectly in

Chapter 3

FIGURE 3-1: The Zen of Python.

Chapter 4

FIGURE 4-1: The hello.py file, open for editing in VS Code.

FIGURE 4-2: The 19.9 is the output from print(extended_price) in the code.

Chapter 5

FIGURE 5-1: Using the sqrt() function from the math module.

FIGURE 5-2: A super simple f-string for formatting.

Chapter 6

FIGURE 6-1: The result of a simple if when the condition proves true.

FIGURE 6-2: Print an initial greeting based on the time of day.

FIGURE 6-3: Looping through a list.

FIGURE 6-4: Nested loops.

FIGURE 6-5: An infinite while loop.

FIGURE 6-6: A while loop with

Chapter 7

FIGURE 7-1: Seeing whether an item is in a list.

FIGURE 7-2: Program fails when trying to find the index of a nonexistent list i...

Chapter 8

FIGURE 8-1: Writing, and calling, a simple function named

FIGURE 8-2: A sample function with a couple of comments added.

FIGURE 8-3: Passing data to a function via a variable.

FIGURE 8-4: The hello function with three parameters.

FIGURE 8-5: Calling the hello() function with three parameters, and again with ...

FIGURE 8-6: Calling a function with keyword arguments (kwargs).

FIGURE 8-7: A function accepting any number of arguments with

FIGURE 8-8: Printing a string returned by the alphabetize() function.

Chapter 9

FIGURE 9-1: The showfilecontents.py and people.csv files in a folder in VS Code...

FIGURE 9-2: The contents of the people.csv file in Excel (top) and a text edito...

FIGURE 9-3: The showfilecontents.py file raises an exception.

FIGURE 9-4: The showfilecontents.py file catches the error and displays a frien...

FIGURE 9-5: The correct error message is displayed.

FIGURE 9-6: Code with try, exception handlers, and an else: block for when ther...

Chapter 10

FIGURE 10-1: Common text and binary files.

FIGURE 10-2: The binarycopy.py file copies any binary file.

FIGURE 10-3: Running binarycopy.py added happy_pickle_copy.jpg to the folder.

Chapter 11

FIGURE 11-1: Some data in an Excel spreadsheet.

FIGURE 11-2: Excel spreadsheet data converted to JSON format.

FIGURE 11-3: Some data in a Google Firebase Realtime Database.

FIGURE 11-4: Output from showing one value at a time from each dictionary (see ...

FIGURE 11-5: Changing the value of one key in each dictionary, and removing an ...

Chapter 12

FIGURE 12-1: The client makes a request, and the server sends back a response.

FIGURE 12-2: Different parts of URLs.

FIGURE 12-3: Inspecting HTTP headers with Google Chrome.

FIGURE 12-4: HTTP headers.

FIGURE 12-5: Sample page used for web scraping.

FIGURE 12-6: Some of the code from the sample page for web scraping.

FIGURE 12-7: Web scraping code complete.

Chapter 13

FIGURE 13-1: Python’s built-in functions.

Python Essentials For Dummies
 2024934008, 9781394263479, 9781394263486, 9781394263493

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
Recommend Papers