Contents In Detail

  1. Praise for Python Crash Course
  2. Title Page
  3. Copyright
  4. Dedication
  5. About the Author
  6. Preface to the Third Edition
  7. Acknowledgments
  8. Introduction
    1. Who Is This Book For?
    2. What Can You Expect to Learn?
    3. Online Resources
    4. Why Python?
  9. Part I: Basics
    1. Chapter 1: Getting Started
      1. Setting Up Your Programming Environment
        1. Python Versions
        2. Running Snippets of Python Code
        3. About the VS Code Editor
      2. Python on Different Operating Systems
        1. Python on Windows
        2. Python on macOS
        3. Python on Linux
      3. Running a Hello World Program
        1. Installing the Python Extension for VS Code
        2. Running hello_world.py
      4. Troubleshooting
      5. Running Python Programs from a Terminal
        1. On Windows
        2. On macOS and Linux
        3. Exercise 1-1: python.org
        4. Exercise 1-2: Hello World Typos
        5. Exercise 1-3: Infinite Skills
      6. Summary
    2. Chapter 2: Variables and Simple Data Types
      1. What Really Happens When You Run hello_world.py
      2. Variables
        1. Naming and Using Variables
        2. Avoiding Name Errors When Using Variables
        3. Variables Are Labels
        4. Exercise 2-1: Simple Message
        5. Exercise 2-2: Simple Messages
      3. Strings
        1. Changing Case in a String with Methods
        2. Using Variables in Strings
        3. Adding Whitespace to Strings with Tabs or Newlines
        4. Stripping Whitespace
        5. Removing Prefixes
        6. Avoiding Syntax Errors with Strings
        7. Exercise 2-3: Personal Message
        8. Exercise 2-4: Name Cases
        9. Exercise 2-5: Famous Quote
        10. Exercise 2-6: Famous Quote 2
        11. Exercise 2-7: Stripping Names
        12. Exercise 2-8: File Extensions
      4. Numbers
        1. Integers
        2. Floats
        3. Integers and Floats
        4. Underscores in Numbers
        5. Multiple Assignment
        6. Constants
        7. Exercise 2-9: Number Eight
        8. Exercise 2-10: Favorite Number
      5. Comments
        1. How Do You Write Comments?
        2. What Kinds of Comments Should You Write?
        3. Exercise 2-11: Adding Comments
      6. The Zen of Python
        1. Exercise 2-12: Zen of Python
      7. Summary
    3. Chapter 3: Introducing Lists
      1. What Is a List?
        1. Accessing Elements in a List
        2. Index Positions Start at 0, Not 1
        3. Using Individual Values from a List
        4. Exercise 3-1: Names
        5. Exercise 3-2: Greetings
        6. Exercise 3-3: Your Own List
      2. Modifying, Adding, and Removing Elements
        1. Modifying Elements in a List
        2. Adding Elements to a List
        3. Removing Elements from a List
        4. Exercise 3-4: Guest List
        5. Exercise 3-5: Changing Guest List
        6. Exercise 3-6: More Guests
        7. Exercise 3-7: Shrinking Guest List
      3. Organizing a List
        1. Sorting a List Permanently with the sort() Method
        2. Sorting a List Temporarily with the sorted() Function
        3. Printing a List in Reverse Order
        4. Finding the Length of a List
        5. Exercise 3-8: Seeing the World
        6. Exercise 3-9: Dinner Guests
        7. Exercise 3-10: Every Function
      4. Avoiding Index Errors When Working with Lists
        1. Exercise 3-11: Intentional Error
      5. Summary
    4. Chapter 4: Working with Lists
      1. Looping Through an Entire List
        1. A Closer Look at Looping
        2. Doing More Work Within a for Loop
        3. Doing Something After a for Loop
      2. Avoiding Indentation Errors
        1. Forgetting to Indent
        2. Forgetting to Indent Additional Lines
        3. Indenting Unnecessarily
        4. Indenting Unnecessarily After the Loop
        5. Forgetting the Colon
        6. Exercise 4-1: Pizzas
        7. Exercise 4-2: Animals
      3. Making Numerical Lists
        1. Using the range() Function
        2. Using range() to Make a List of Numbers
        3. Simple Statistics with a List of Numbers
        4. List Comprehensions
        5. Exercise 4-3: Counting to Twenty
        6. Exercise 4-4: One Million
        7. Exercise 4-5: Summing a Million
        8. Exercise 4-6: Odd Numbers
        9. Exercise 4-7: Threes
        10. Exercise 4-8: Cubes
        11. Exercise 4-9: Cube Comprehension
      4. Working with Part of a List
        1. Slicing a List
        2. Looping Through a Slice
        3. Copying a List
        4. Exercise 4-10: Slices
        5. Exercise 4-11: My Pizzas, Your Pizzas
        6. Exercise 4-12: More Loops
      5. Tuples
        1. Defining a Tuple
        2. Looping Through All Values in a Tuple
        3. Writing Over a Tuple
        4. Exercise 4-13: Buffet
      6. Styling Your Code
        1. The Style Guide
        2. Indentation
        3. Line Length
        4. Blank Lines
        5. Other Style Guidelines
        6. Exercise 4-14: PEP 8
        7. Exercise 4-15: Code Review
      7. Summary
    5. Chapter 5: if Statements
      1. A Simple Example
      2. Conditional Tests
        1. Checking for Equality
        2. Ignoring Case When Checking for Equality
        3. Checking for Inequality
        4. Numerical Comparisons
        5. Checking Multiple Conditions
        6. Checking Whether a Value Is in a List
        7. Checking Whether a Value Is Not in a List
        8. Boolean Expressions
        9. Exercise 5-1: Conditional Tests
        10. Exercise 5-2: More Conditional Tests
      3. if Statements
        1. Simple if Statements
        2. if-else Statements
        3. The if-elif-else Chain
        4. Using Multiple elif Blocks
        5. Omitting the else Block
        6. Testing Multiple Conditions
        7. Exercise 5-3: Alien Colors #1
        8. Exercise 5-4: Alien Colors #2
        9. Exercise 5-5: Alien Colors #3
        10. Exercise 5-6: Stages of Life
        11. Exercise 5-7: Favorite Fruit
      4. Using if Statements with Lists
        1. Checking for Special Items
        2. Checking That a List Is Not Empty
        3. Using Multiple Lists
        4. Exercise 5-8: Hello Admin
        5. Exercise 5-9: No Users
        6. Exercise 5-10: Checking Usernames
        7. Exercise 5-11: Ordinal Numbers
      5. Styling Your if Statements
        1. Exercise 5-12: Styling if Statements
        2. Exercise 5-13: Your Ideas
      6. Summary
    6. Chapter 6: Dictionaries
      1. A Simple Dictionary
      2. Working with Dictionaries
        1. Accessing Values in a Dictionary
        2. Adding New Key-Value Pairs
        3. Starting with an Empty Dictionary
        4. Modifying Values in a Dictionary
        5. Removing Key-Value Pairs
        6. A Dictionary of Similar Objects
        7. Using get() to Access Values
        8. Exercise 6-1: Person
        9. Exercise 6-2: Favorite Numbers
        10. Exercise 6-3: Glossary
      3. Looping Through a Dictionary
        1. Looping Through All Key-Value Pairs
        2. Looping Through All the Keys in a Dictionary
        3. Looping Through a Dictionary’s Keys in a Particular Order
        4. Looping Through All Values in a Dictionary
        5. Exercise 6-4: Glossary 2
        6. Exercise 6-5: Rivers
        7. Exercise 6-6: Polling
      4. Nesting
        1. A List of Dictionaries
        2. A List in a Dictionary
        3. A Dictionary in a Dictionary
        4. Exercise 6-7: People
        5. Exercise 6-8: Pets
        6. Exercise 6-9: Favorite Places
        7. Exercise 6-10: Favorite Numbers
        8. Exercise 6-11: Cities
        9. Exercise 6-12: Extensions
      5. Summary
    7. Chapter 7: User Input and while Loops
      1. How the input() Function Works
        1. Writing Clear Prompts
        2. Using int() to Accept Numerical Input
        3. The Modulo Operator
        4. Exercise 7-1: Rental Car
        5. Exercise 7-2: Restaurant Seating
        6. Exercise 7-3: Multiples of Ten
      2. Introducing while Loops
        1. The while Loop in Action
        2. Letting the User Choose When to Quit
        3. Using a Flag
        4. Using break to Exit a Loop
        5. Using continue in a Loop
        6. Avoiding Infinite Loops
        7. Exercise 7-4: Pizza Toppings
        8. Exercise 7-5: Movie Tickets
        9. Exercise 7-6: Three Exits
        10. Exercise 7-7: Infinity
      3. Using a while Loop with Lists and Dictionaries
        1. Moving Items from One List to Another
        2. Removing All Instances of Specific Values from a List
        3. Filling a Dictionary with User Input
        4. Exercise 7-8: Deli
        5. Exercise 7-9: No Pastrami
        6. Exercise 7-10: Dream Vacation
      4. Summary
    8. Chapter 8: Functions
      1. Defining a Function
        1. Passing Information to a Function
        2. Arguments and Parameters
        3. Exercise 8-1: Message
        4. Exercise 8-2: Favorite Book
      2. Passing Arguments
        1. Positional Arguments
        2. Keyword Arguments
        3. Default Values
        4. Equivalent Function Calls
        5. Avoiding Argument Errors
        6. Exercise 8-3: T-Shirt
        7. Exercise 8-4: Large Shirts
        8. Exercise 8-5: Cities
      3. Return Values
        1. Returning a Simple Value
        2. Making an Argument Optional
        3. Returning a Dictionary
        4. Using a Function with a while Loop
        5. Exercise 8-6: City Names
        6. Exercise 8-7: Album
        7. Exercise 8-8: User Albums
      4. Passing a List
        1. Modifying a List in a Function
        2. Preventing a Function from Modifying a List
        3. Exercise 8-9: Messages
        4. Exercise 8-10: Sending Messages
        5. Exercise 8-11: Archived Messages
      5. Passing an Arbitrary Number of Arguments
        1. Mixing Positional and Arbitrary Arguments
        2. Using Arbitrary Keyword Arguments
        3. Exercise 8-12: Sandwiches
        4. Exercise 8-13: User Profile
        5. Exercise 8-14: Cars
      6. Storing Your Functions in Modules
        1. Importing an Entire Module
        2. Importing Specific Functions
        3. Using as to Give a Function an Alias
        4. Using as to Give a Module an Alias
        5. Importing All Functions in a Module
      7. Styling Functions
        1. Exercise 8-15: Printing Models
        2. Exercise 8-16: Imports
        3. Exercise 8-17: Styling Functions
      8. Summary
    9. Chapter 9: Classes
      1. Creating and Using a Class
        1. Creating the Dog Class
        2. The __init__() Method
        3. Making an Instance from a Class
        4. Exercise 9-1: Restaurant
        5. Exercise 9-2: Three Restaurants
        6. Exercise 9-3: Users
      2. Working with Classes and Instances
        1. The Car Class
        2. Setting a Default Value for an Attribute
        3. Modifying Attribute Values
        4. Exercise 9-4: Number Served
        5. Exercise 9-5: Login Attempts
      3. Inheritance
        1. The __init__() Method for a Child Class
        2. Defining Attributes and Methods for the Child Class
        3. Overriding Methods from the Parent Class
        4. Instances as Attributes
        5. Modeling Real-World Objects
        6. Exercise 9-6: Ice Cream Stand
        7. Exercise 9-7: Admin
        8. Exercise 9-8: Privileges
        9. Exercise 9-9: Battery Upgrade
      4. Importing Classes
        1. Importing a Single Class
        2. Storing Multiple Classes in a Module
        3. Importing Multiple Classes from a Module
        4. Importing an Entire Module
        5. Importing All Classes from a Module
        6. Importing a Module into a Module
        7. Using Aliases
        8. Finding Your Own Workflow
        9. Exercise 9-10: Imported Restaurant
        10. Exercise 9-11: Imported Admin
        11. Exercise 9-12: Multiple Modules
      5. The Python Standard Library
        1. Exercise 9-13: Dice
        2. Exercise 9-14: Lottery
        3. Exercise 9-15: Lottery Analysis
        4. Exercise 9-16: Python Module of the Week
      6. Styling Classes
      7. Summary
    10. Chapter 10: Files and Exceptions
      1. Reading from a File
        1. Reading the Contents of a File
        2. Relative and Absolute File Paths
        3. Accessing a File’s Lines
        4. Working with a File’s Contents
        5. Large Files: One Million Digits
        6. Is Your Birthday Contained in Pi?
        7. Exercise 10-1: Learning Python
        8. Exercise 10-2: Learning C
        9. Exercise 10-3: Simpler Code
      2. Writing to a File
        1. Writing a Single Line
        2. Writing Multiple Lines
        3. Exercise 10-4: Guest
        4. Exercise 10-5: Guest Book
      3. Exceptions
        1. Handling the ZeroDivisionError Exception
        2. Using try-except Blocks
        3. Using Exceptions to Prevent Crashes
        4. The else Block
        5. Handling the FileNotFoundError Exception
        6. Analyzing Text
        7. Working with Multiple Files
        8. Failing Silently
        9. Deciding Which Errors to Report
        10. Exercise 10-6: Addition
        11. Exercise 10-7: Addition Calculator
        12. Exercise 10-8: Cats and Dogs
        13. Exercise 10-9: Silent Cats and Dogs
        14. Exercise 10-10: Common Words
      4. Storing Data
        1. Using json.dumps() and json.loads()
        2. Saving and Reading User-Generated Data
        3. Refactoring
        4. Exercise 10-11: Favorite Number
        5. Exercise 10-12: Favorite Number Remembered
        6. Exercise 10-13: User Dictionary
        7. Exercise 10-14: Verify User
      5. Summary
    11. Chapter 11: Testing Your Code
      1. Installing pytest with pip
        1. Updating pip
        2. Installing pytest
      2. Testing a Function
        1. Unit Tests and Test Cases
        2. A Passing Test
        3. Running a Test
        4. A Failing Test
        5. Responding to a Failed Test
        6. Adding New Tests
        7. Exercise 11-1: City, Country
        8. Exercise 11-2: Population
      3. Testing a Class
        1. A Variety of Assertions
        2. A Class to Test
        3. Testing the AnonymousSurvey Class
        4. Using Fixtures
        5. Exercise 11-3: Employee
      4. Summary
  10. Part II: Projects
    1. Chapter 12: A Ship That Fires Bullets
      1. Planning Your Project
      2. Installing Pygame
      3. Starting the Game Project
        1. Creating a Pygame Window and Responding to User Input
        2. Controlling the Frame Rate
        3. Setting the Background Color
        4. Creating a Settings Class
      4. Adding the Ship Image
        1. Creating the Ship Class
        2. Drawing the Ship to the Screen
      5. Refactoring: The _check_events() and _update_screen() Methods
        1. The _check_events() Method
        2. The _update_screen() Method
        3. Exercise 12-1: Blue Sky
        4. Exercise 12-2: Game Character
      6. Piloting the Ship
        1. Responding to a Keypress
        2. Allowing Continuous Movement
        3. Moving Both Left and Right
        4. Adjusting the Ship’s Speed
        5. Limiting the Ship’s Range
        6. Refactoring _check_events()
        7. Pressing Q to Quit
        8. Running the Game in Fullscreen Mode
      7. A Quick Recap
        1. alien_invasion.py
        2. settings.py
        3. ship.py
        4. Exercise 12-3: Pygame Documentation
        5. Exercise 12-4: Rocket
        6. Exercise 12-5: Keys
      8. Shooting Bullets
        1. Adding the Bullet Settings
        2. Creating the Bullet Class
        3. Storing Bullets in a Group
        4. Firing Bullets
        5. Deleting Old Bullets
        6. Limiting the Number of Bullets
        7. Creating the _update_bullets() Method
        8. Exercise 12-6: Sideways Shooter
      9. Summary
    2. Chapter 13: Aliens!
      1. Reviewing the Project
      2. Creating the First Alien
        1. Creating the Alien Class
        2. Creating an Instance of the Alien
      3. Building the Alien Fleet
        1. Creating a Row of Aliens
        2. Refactoring _create_fleet()
        3. Adding Rows
        4. Exercise 13-1: Stars
        5. Exercise 13-2: Better Stars
      4. Making the Fleet Move
        1. Moving the Aliens Right
        2. Creating Settings for Fleet Direction
        3. Checking Whether an Alien Has Hit the Edge
        4. Dropping the Fleet and Changing Direction
        5. Exercise 13-3: Raindrops
        6. Exercise 13-4: Steady Rain
      5. Shooting Aliens
        1. Detecting Bullet Collisions
        2. Making Larger Bullets for Testing
        3. Repopulating the Fleet
        4. Speeding Up the Bullets
        5. Refactoring _update_bullets()
        6. Exercise 13-5: Sideways Shooter Part 2
      6. Ending the Game
        1. Detecting Alien-Ship Collisions
        2. Responding to Alien-Ship Collisions
        3. Aliens That Reach the Bottom of the Screen
        4. Game Over!
        5. Identifying When Parts of the Game Should Run
        6. Exercise 13-6: Game Over
      7. Summary
    3. Chapter 14: Scoring
      1. Adding the Play Button
        1. Creating a Button Class
        2. Drawing the Button to the Screen
        3. Starting the Game
        4. Resetting the Game
        5. Deactivating the Play Button
        6. Hiding the Mouse Cursor
        7. Exercise 14-1: Press P to Play
        8. Exercise 14-2: Target Practice
      2. Leveling Up
        1. Modifying the Speed Settings
        2. Resetting the Speed
        3. Exercise 14-3: Challenging Target Practice
        4. Exercise 14-4: Difficulty Levels
      3. Scoring
        1. Displaying the Score
        2. Making a Scoreboard
        3. Updating the Score as Aliens Are Shot Down
        4. Resetting the Score
        5. Making Sure to Score All Hits
        6. Increasing Point Values
        7. Rounding the Score
        8. High Scores
        9. Displaying the Level
        10. Displaying the Number of Ships
        11. Exercise 14-5: All-Time High Score
        12. Exercise 14-6: Refactoring
        13. Exercise 14-7: Expanding the Game
        14. Exercise 14-8: Sideways Shooter, Final Version
      4. Summary
    4. Chapter 15: Generating Data
      1. Installing Matplotlib
      2. Plotting a Simple Line Graph
        1. Changing the Label Type and Line Thickness
        2. Correcting the Plot
        3. Using Built-in Styles
        4. Plotting and Styling Individual Points with scatter()
        5. Plotting a Series of Points with scatter()
        6. Calculating Data Automatically
        7. Customizing Tick Labels
        8. Defining Custom Colors
        9. Using a Colormap
        10. Saving Your Plots Automatically
        11. Exercise 15-1: Cubes
        12. Exercise 15-2: Colored Cubes
      3. Random Walks
        1. Creating the RandomWalk Class
        2. Choosing Directions
        3. Plotting the Random Walk
        4. Generating Multiple Random Walks
        5. Styling the Walk
        6. Exercise 15-3: Molecular Motion
        7. Exercise 15-4: Modified Random Walks
        8. Exercise 15-5: Refactoring
      4. Rolling Dice with Plotly
        1. Installing Plotly
        2. Creating the Die Class
        3. Rolling the Die
        4. Analyzing the Results
        5. Making a Histogram
        6. Customizing the Plot
        7. Rolling Two Dice
        8. Further Customizations
        9. Rolling Dice of Different Sizes
        10. Saving Figures
        11. Exercise 15-6: Two D8s
        12. Exercise 15-7: Three Dice
        13. Exercise 15-8: Multiplication
        14. Exercise 15-9: Die Comprehensions
        15. Exercise 15-10: Practicing with Both Libraries
      5. Summary
    5. Chapter 16: Downloading Data
      1. The CSV File Format
        1. Parsing the CSV File Headers
        2. Printing the Headers and Their Positions
        3. Extracting and Reading Data
        4. Plotting Data in a Temperature Chart
        5. The datetime Module
        6. Plotting Dates
        7. Plotting a Longer Timeframe
        8. Plotting a Second Data Series
        9. Shading an Area in the Chart
        10. Error Checking
        11. Downloading Your Own Data
        12. Exercise 16-1: Sitka Rainfall
        13. Exercise 16-2: Sitka–Death Valley Comparison
        14. Exercise 16-3: San Francisco
        15. Exercise 16-4: Automatic Indexes
        16. Exercise 16-5: Explore
      2. Mapping Global Datasets: GeoJSON Format
        1. Downloading Earthquake Data
        2. Examining GeoJSON Data
        3. Making a List of All Earthquakes
        4. Extracting Magnitudes
        5. Extracting Location Data
        6. Building a World Map
        7. Representing Magnitudes
        8. Customizing Marker Colors
        9. Other Color Scales
        10. Adding Hover Text
        11. Exercise 16-6: Refactoring
        12. Exercise 16-7: Automated Title
        13. Exercise 16-8: Recent Earthquakes
        14. Exercise 16-9: World Fires
      3. Summary
    6. Chapter 17: Working with APIs
      1. Using an API
        1. Git and GitHub
        2. Requesting Data Using an API Call
        3. Installing Requests
        4. Processing an API Response
        5. Working with the Response Dictionary
        6. Summarizing the Top Repositories
        7. Monitoring API Rate Limits
      2. Visualizing Repositories Using Plotly
        1. Styling the Chart
        2. Adding Custom Tooltips
        3. Adding Clickable Links
        4. Customizing Marker Colors
        5. More About Plotly and the GitHub API
      3. The Hacker News API
        1. Exercise 17-1: Other Languages
        2. Exercise 17-2: Active Discussions
        3. Exercise 17-3: Testing python_repos.py
        4. Exercise 17-4: Further Exploration
      4. Summary
    7. Chapter 18: Getting Started with Django
      1. Setting Up a Project
        1. Writing a Spec
        2. Creating a Virtual Environment
        3. Activating the Virtual Environment
        4. Installing Django
        5. Creating a Project in Django
        6. Creating the Database
        7. Viewing the Project
        8. Exercise 18-1: New Projects
      2. Starting an App
        1. Defining Models
        2. Activating Models
        3. The Django Admin Site
        4. Defining the Entry Model
        5. Migrating the Entry Model
        6. Registering Entry with the Admin Site
        7. The Django Shell
        8. Exercise 18-2: Short Entries
        9. Exercise 18-3: The Django API
        10. Exercise 18-4: Pizzeria
      3. Making Pages: The Learning Log Home Page
        1. Mapping a URL
        2. Writing a View
        3. Writing a Template
        4. Exercise 18-5: Meal Planner
        5. Exercise 18-6: Pizzeria Home Page
      4. Building Additional Pages
        1. Template Inheritance
        2. The Topics Page
        3. Individual Topic Pages
        4. Exercise 18-7: Template Documentation
        5. Exercise 18-8: Pizzeria Pages
      5. Summary
    8. Chapter 19: User Accounts
      1. Allowing Users to Enter Data
        1. Adding New Topics
        2. Adding New Entries
        3. Editing Entries
        4. Exercise 19-1: Blog
      2. Setting Up User Accounts
        1. The accounts App
        2. The Login Page
        3. Logging Out
        4. The Registration Page
        5. Exercise 19-2: Blog Accounts
      3. Allowing Users to Own Their Data
        1. Restricting Access with @login_required
        2. Connecting Data to Certain Users
        3. Restricting Topics Access to Appropriate Users
        4. Protecting a User’s Topics
        5. Protecting the edit_entry Page
        6. Associating New Topics with the Current User
        7. Exercise 19-3: Refactoring
        8. Exercise 19-4: Protecting new_entry
        9. Exercise 19-5: Protected Blog
      4. Summary
    9. Chapter 20: Styling and Deploying an App
      1. Styling Learning Log
        1. The django-bootstrap5 App
        2. Using Bootstrap to Style Learning Log
        3. Modifying base.html
        4. Styling the Home Page Using a Jumbotron
        5. Styling the Login Page
        6. Styling the Topics Page
        7. Styling the Entries on the Topic Page
        8. Exercise 20-1: Other Forms
        9. Exercise 20-2: Stylish Blog
      2. Deploying Learning Log
        1. Making a Platform.sh Account
        2. Installing the Platform.sh CLI
        3. Installing platformshconfig
        4. Creating a requirements.txt File
        5. Additional Deployment Requirements
        6. Adding Configuration Files
        7. Modifying settings.py for Platform.sh
        8. Using Git to Track the Project’s Files
        9. Creating a Project on Platform.sh
        10. Pushing to Platform.sh
        11. Viewing the Live Project
        12. Refining the Platform.sh Deployment
        13. Creating Custom Error Pages
        14. Ongoing Development
        15. Deleting a Project on Platform.sh
        16. Exercise 20-3: Live Blog
        17. Exercise 20-4: Extended Learning Log
      3. Summary
  11. Appendix A: Installation and Troubleshooting
    1. Python on Windows
      1. Using py Instead of python
      2. Rerunning the Installer
    2. Python on macOS
      1. Accidentally Installing Apple’s Version of Python
      2. Python 2 on Older Versions of macOS
    3. Python on Linux
      1. Using the Default Python Installation
      2. Installing the Latest Version of Python
    4. Checking Which Version of Python You’re Using
    5. Python Keywords and Built-in Functions
      1. Python Keywords
      2. Python Built-in Functions
  12. Appendix B: Text Editors and IDEs
    1. Working Efficiently with VS Code
      1. Configuring VS Code
      2. VS Code Shortcuts
    2. Other Text Editors and IDEs
      1. IDLE
      2. Geany
      3. Sublime Text
      4. Emacs and Vim
      5. PyCharm
      6. Jupyter Notebooks
  13. Appendix C: Getting Help
    1. First Steps
      1. Try It Again
      2. Take a Break
      3. Refer to This Book’s Resources
    2. Searching Online
      1. Stack Overflow
      2. The Official Python Documentation
      3. Official Library Documentation
      4. r/learnpython
      5. Blog Posts
    3. Discord
    4. Slack
  14. Appendix D: Using Git for Version Control
    1. Installing Git
      1. Configuring Git
    2. Making a Project
    3. Ignoring Files
    4. Initializing a Repository
    5. Checking the Status
    6. Adding Files to the Repository
    7. Making a Commit
    8. Checking the Log
    9. The Second Commit
    10. Abandoning Changes
    11. Checking Out Previous Commits
    12. Deleting the Repository
  15. Appendix E: Troubleshooting Deployments
    1. Understanding Deployments
    2. Basic Troubleshooting
      1. Follow Onscreen Suggestions
      2. Read the Log Output
    3. OS-Specific Troubleshooting
      1. Deploying from Windows
      2. Deploying from macOS
      3. Deploying from Linux
    4. Other Deployment Approaches
  16. Index

List of Tables

  1. Table 11-1: Commonly Used Assertion Statements in Tests
  2. Table 16-1: Date and Time Formatting Arguments from the datetime Module

List of Illustrations

  1. Figure 1-1: Make sure you select the checkbox labeled Add Python to PATH.
  2. Figure 12-1: The ship for Alien Invasion
  3. Figure 12-2: Alien Invasion with the ship at the bottom center of the screen
  4. Figure 12-3: The ship after firing a series of bullets
  5. Figure 13-1: The alien we’ll use to build the fleet
  6. Figure 13-2: The first alien appears.
  7. Figure 13-3: The first row of aliens
  8. Figure 13-4: The full fleet appears.
  9. Figure 13-5: We can shoot aliens!
  10. Figure 13-6: Extra-powerful bullets make some aspects of the game easier to test.
  11. Figure 14-1: A Play button appears when the game is inactive.
  12. Figure 14-2: The score appears at the top-right corner of the screen.
  13. Figure 14-3: A rounded score with comma separators
  14. Figure 14-4: The high score is shown at the top center of the screen.
  15. Figure 14-5: The current level appears just below the current score.
  16. Figure 14-6: The complete scoring system for Alien Invasion
  17. Figure 15-1: One of the simplest plots you can make in Matplotlib
  18. Figure 15-2: The chart is much easier to read now.
  19. Figure 15-3: The data is now plotted correctly.
  20. Figure 15-4: The built-in seaborn style
  21. Figure 15-5: Plotting a single point
  22. Figure 15-6: A scatter plot with multiple points
  23. Figure 15-7: Python can plot 1,000 points as easily as it plots 5 points.
  24. Figure 15-8: A plot using the Blues colormap
  25. Figure 15-9: A random walk with 5,000 points
  26. Figure 15-10: A random walk colored with the Blues colormap
  27. Figure 15-11: A walk with 50,000 points
  28. Figure 15-12: The initial plot produced by Plotly Express
  29. Figure 15-13: A simple bar chart created with Plotly
  30. Figure 15-14: Simulated results of rolling two six-sided dice 1,000 times
  31. Figure 15-15: The results of rolling a six-sided die and a ten-sided die 50,000 times
  32. Figure 16-1: A line graph showing daily high temperatures for July 2021 in Sitka, Alaska
  33. Figure 16-2: The graph is more meaningful, now that it has dates on the x-axis.
  34. Figure 16-3: A year’s worth of data
  35. Figure 16-4: Two data series on the same plot
  36. Figure 16-5: The region between the two datasets is shaded.
  37. Figure 16-6: Daily high and low temperatures for Death Valley
  38. Figure 16-7: A simple map showing where all the earthquakes in the last 24 hours occurred
  39. Figure 16-8: The map now shows the magnitude of all earthquakes in the last 30 days.
  40. Figure 16-9: In 30 days’ worth of earthquakes, color and size are used to represent the magnitude of each earthquake.
  41. Figure 16-10: The hover text now includes a summary of each earthquake.
  42. Figure 17-1: The most-starred Python projects on GitHub
  43. Figure 17-2: A title has been added to the main chart, and to each axis as well.
  44. Figure 17-3: Hovering over a bar shows the project’s owner and description.
  45. Figure 18-1: Everything is working so far.
  46. Figure 18-2: The admin site with Topic included
  47. Figure 18-3: The home page for Learning Log
  48. Figure 18-4: The topics page
  49. Figure 18-5: The detail page for a single topic, showing all entries for a topic
  50. Figure 19-1: The page for adding a new topic
  51. Figure 19-2: The new_entry page
  52. Figure 19-3: Each entry now has a link for editing that entry.
  53. Figure 19-4: The login page
  54. Figure 20-1: The Learning Log home page using Bootstrap
  55. Figure 20-2: The login page styled with Bootstrap
  56. Figure 20-3: The topic page with Bootstrap styling

List of Listings

Guide

  1. Cover
  2. Front Matter
  3. Dedication
  4. Preface to the Third Edition
  5. Introduction
  6. Part I: Basics
  7. Chapter 1: Getting Started
  8. Start Reading
  9. Chapter 2: Variables and Simple Data Types
  10. Chapter 3: Introducing Lists
  11. Chapter 4: Working with Lists
  12. Chapter 5: if Statements
  13. Chapter 6: Dictionaries
  14. Chapter 7: User Input and while Loops
  15. Chapter 8: Functions
  16. Chapter 9: Classes
  17. Chapter 10: Files and Exceptions
  18. Chapter 11: Testing Your Code
  19. Part II: Projects
  20. Chapter 12: A Ship That Fires Bullets
  21. Chapter 13: Aliens!
  22. Chapter 14: Scoring
  23. Chapter 15: Generating Data
  24. Chapter 16: Downloading Data
  25. Chapter 17: Working with APIs
  26. Chapter 18: Getting Started with Django
  27. Chapter 19: User Accounts
  28. Chapter 20: Styling and Deploying an App
  29. Appendix A: Installation and Troubleshooting
  30. Appendix B: Text Editors and IDEs
  31. Appendix C: Getting Help
  32. Appendix D: Using Git for Version Control
  33. Appendix E: Troubleshooting Deployments
  34. Index

Pages

  1. i
  2. iii
  3. iv
  4. v
  5. vii
  6. xxvii
  7. xxviii
  8. xxix
  9. xxxi
  10. xxxii
  11. xxxiii
  12. xxxiv
  13. xxxv
  14. xxxvi
  15. 1
  16. 2
  17. 3
  18. 4
  19. 5
  20. 6
  21. 7
  22. 8
  23. 9
  24. 10
  25. 11
  26. 12
  27. 13
  28. 15
  29. 16
  30. 17
  31. 18
  32. 19
  33. 20
  34. 21
  35. 22
  36. 23
  37. 24
  38. 25
  39. 26
  40. 27
  41. 28
  42. 29
  43. 30
  44. 31
  45. 32
  46. 33
  47. 34
  48. 35
  49. 36
  50. 37
  51. 38
  52. 39
  53. 40
  54. 41
  55. 42
  56. 43
  57. 44
  58. 45
  59. 46
  60. 47
  61. 49
  62. 50
  63. 51
  64. 52
  65. 53
  66. 54
  67. 55
  68. 56
  69. 57
  70. 58
  71. 59
  72. 60
  73. 61
  74. 62
  75. 63
  76. 64
  77. 65
  78. 66
  79. 67
  80. 68
  81. 69
  82. 70
  83. 71
  84. 72
  85. 73
  86. 74
  87. 75
  88. 76
  89. 77
  90. 78
  91. 79
  92. 80
  93. 81
  94. 82
  95. 83
  96. 84
  97. 85
  98. 86
  99. 87
  100. 88
  101. 89
  102. 91
  103. 92
  104. 93
  105. 94
  106. 95
  107. 96
  108. 97
  109. 98
  110. 99
  111. 100
  112. 101
  113. 102
  114. 103
  115. 104
  116. 105
  117. 106
  118. 107
  119. 108
  120. 109
  121. 110
  122. 111
  123. 112
  124. 113
  125. 114
  126. 115
  127. 116
  128. 117
  129. 118
  130. 119
  131. 120
  132. 121
  133. 122
  134. 123
  135. 124
  136. 125
  137. 126
  138. 127
  139. 129
  140. 130
  141. 131
  142. 132
  143. 133
  144. 134
  145. 135
  146. 136
  147. 137
  148. 138
  149. 139
  150. 140
  151. 141
  152. 142
  153. 143
  154. 144
  155. 145
  156. 146
  157. 147
  158. 148
  159. 149
  160. 150
  161. 151
  162. 152
  163. 153
  164. 154
  165. 155
  166. 157
  167. 158
  168. 159
  169. 160
  170. 161
  171. 162
  172. 163
  173. 164
  174. 165
  175. 166
  176. 167
  177. 168
  178. 169
  179. 170
  180. 171
  181. 172
  182. 173
  183. 174
  184. 175
  185. 176
  186. 177
  187. 178
  188. 179
  189. 180
  190. 181
  191. 183
  192. 184
  193. 185
  194. 186
  195. 187
  196. 188
  197. 189
  198. 190
  199. 191
  200. 192
  201. 193
  202. 194
  203. 195
  204. 196
  205. 197
  206. 198
  207. 199
  208. 200
  209. 201
  210. 202
  211. 203
  212. 204
  213. 205
  214. 206
  215. 207
  216. 209
  217. 210
  218. 211
  219. 212
  220. 213
  221. 214
  222. 215
  223. 216
  224. 217
  225. 218
  226. 219
  227. 220
  228. 221
  229. 222
  230. 223
  231. 225
  232. 226
  233. 227
  234. 228
  235. 229
  236. 230
  237. 231
  238. 232
  239. 233
  240. 234
  241. 235
  242. 236
  243. 237
  244. 238
  245. 239
  246. 240
  247. 241
  248. 242
  249. 243
  250. 244
  251. 245
  252. 246
  253. 247
  254. 248
  255. 249
  256. 250
  257. 251
  258. 252
  259. 253
  260. 255
  261. 256
  262. 257
  263. 258
  264. 259
  265. 260
  266. 261
  267. 262
  268. 263
  269. 264
  270. 265
  271. 266
  272. 267
  273. 268
  274. 269
  275. 270
  276. 271
  277. 272
  278. 273
  279. 274
  280. 275
  281. 276
  282. 277
  283. 278
  284. 279
  285. 280
  286. 281
  287. 282
  288. 283
  289. 284
  290. 285
  291. 286
  292. 287
  293. 288
  294. 289
  295. 290
  296. 291
  297. 292
  298. 293
  299. 294
  300. 295
  301. 296
  302. 297
  303. 298
  304. 299
  305. 301
  306. 302
  307. 303
  308. 304
  309. 305
  310. 306
  311. 307
  312. 308
  313. 309
  314. 310
  315. 311
  316. 312
  317. 313
  318. 314
  319. 315
  320. 316
  321. 317
  322. 318
  323. 319
  324. 320
  325. 321
  326. 322
  327. 323
  328. 324
  329. 325
  330. 326
  331. 327
  332. 328
  333. 329
  334. 330
  335. 331
  336. 332
  337. 333
  338. 334
  339. 335
  340. 336
  341. 337
  342. 338
  343. 339
  344. 340
  345. 341
  346. 342
  347. 343
  348. 344
  349. 345
  350. 346
  351. 347
  352. 348
  353. 349
  354. 350
  355. 351
  356. 352
  357. 353
  358. 355
  359. 356
  360. 357
  361. 358
  362. 359
  363. 360
  364. 361
  365. 362
  366. 363
  367. 364
  368. 365
  369. 366
  370. 367
  371. 368
  372. 369
  373. 370
  374. 371
  375. 372
  376. 373
  377. 374
  378. 375
  379. 376
  380. 377
  381. 378
  382. 379
  383. 380
  384. 381
  385. 382
  386. 383
  387. 384
  388. 385
  389. 386
  390. 387
  391. 388
  392. 389
  393. 390
  394. 391
  395. 392
  396. 393
  397. 394
  398. 395
  399. 396
  400. 397
  401. 398
  402. 399
  403. 400
  404. 401
  405. 403
  406. 404
  407. 405
  408. 406
  409. 407
  410. 408
  411. 409
  412. 410
  413. 411
  414. 412
  415. 413
  416. 414
  417. 415
  418. 416
  419. 417
  420. 418
  421. 419
  422. 420
  423. 421
  424. 422
  425. 423
  426. 424
  427. 425
  428. 426
  429. 427
  430. 428
  431. 429
  432. 430
  433. 431
  434. 433
  435. 434
  436. 435
  437. 436
  438. 437
  439. 438
  440. 439
  441. 440
  442. 441
  443. 442
  444. 443
  445. 444
  446. 445
  447. 446
  448. 447
  449. 448
  450. 449
  451. 450
  452. 451
  453. 452
  454. 453
  455. 454
  456. 455
  457. 456
  458. 457
  459. 458
  460. 459
  461. 460
  462. 461
  463. 462
  464. 463
  465. 464
  466. 465
  467. 466
  468. 467
  469. 469
  470. 470
  471. 471
  472. 472
  473. 473
  474. 474
  475. 475
  476. 477
  477. 478
  478. 479
  479. 480
  480. 481
  481. 483
  482. 484
  483. 485
  484. 486
  485. 487
  486. 488
  487. 489
  488. 490
  489. 491
  490. 492
  491. 493
  492. 494
  493. 495
  494. 496
  495. 497
  496. 498
  497. 499
  498. 500
  499. 501
  500. 503
  501. 504
  502. 505
  503. 506
  504. 507
  505. 508
  506. 509
  507. 510
  508. 511
  509. 512
  510. 513
  511. 514