Python Crash Course, 3rd Edition

Book description

Python Crash Course is the world's best-selling guide to the Python guide programming language, with over 1,500,000 copies sold to date!

This fast-paced, thorough introduction to programming with Python will have you writing code, solving problems, and making cool projects that work in no time.

In the first half of the book, you'll learn basic programming concepts, such as variables, lists, loops, and classes, and practice writing clean code with exercises for each topic. You'll also learn how to make your programs interactive and test your code safely before adding it to a project. In the second half, you'll put your new knowledge into practice with three substantial projects: a Space Invaders--inspired arcade game, a set of data visualizations with Python's handy libraries, and a simple web app you can deploy online.

As you work through the book, you'll learn how to:

•Use powerful Python libraries and tools, including Pygame, Matplotlib, Plotly, and Django

•Make 2D games that respond to keypresses and mouse clicks

•Use data to generate interactive visualizations

•Create and customize web apps and deploy them safely online

•Deal with mistakes and errors so you can solve your own programming problems

This updated third edition has been thoroughly revised to reflect the latest in Python code and practices. The first half of the book includes improved coverage of topics like variables, handling errors, and object-oriented programming. In the second half, the code for the projects has been updated with current example data, better app deployment, and up-to-date libraries and tools, like Plotly, the Tailwind CSS framework, and the latest version of Django.

If you've been thinking about digging into programming, Python Crash Course will get you writing real programs fast. Why wait any longer? Start your engines and code!

Table of contents

  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

Product information

  • Title: Python Crash Course, 3rd Edition
  • Author(s): Eric Matthes
  • Release date: January 2023
  • Publisher(s): No Starch Press
  • ISBN: 9781718502703