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
- Praise for Python Crash Course
- Title Page
- Copyright
- Dedication
- About the Author
- Preface to the Third Edition
- Acknowledgments
- Introduction
-
Part I: Basics
- Chapter 1: Getting Started
-
Chapter 2: Variables and Simple Data Types
- What Really Happens When You Run hello_world.py
- Variables
-
Strings
- Changing Case in a String with Methods
- Using Variables in Strings
- Adding Whitespace to Strings with Tabs or Newlines
- Stripping Whitespace
- Removing Prefixes
- Avoiding Syntax Errors with Strings
- Exercise 2-3: Personal Message
- Exercise 2-4: Name Cases
- Exercise 2-5: Famous Quote
- Exercise 2-6: Famous Quote 2
- Exercise 2-7: Stripping Names
- Exercise 2-8: File Extensions
- Numbers
- Comments
- The Zen of Python
- Summary
- Chapter 3: Introducing Lists
-
Chapter 4: Working with Lists
- Looping Through an Entire List
- Avoiding Indentation Errors
-
Making Numerical Lists
- Using the range() Function
- Using range() to Make a List of Numbers
- Simple Statistics with a List of Numbers
- List Comprehensions
- Exercise 4-3: Counting to Twenty
- Exercise 4-4: One Million
- Exercise 4-5: Summing a Million
- Exercise 4-6: Odd Numbers
- Exercise 4-7: Threes
- Exercise 4-8: Cubes
- Exercise 4-9: Cube Comprehension
- Working with Part of a List
- Tuples
- Styling Your Code
- Summary
-
Chapter 5: if Statements
- A Simple Example
-
Conditional Tests
- Checking for Equality
- Ignoring Case When Checking for Equality
- Checking for Inequality
- Numerical Comparisons
- Checking Multiple Conditions
- Checking Whether a Value Is in a List
- Checking Whether a Value Is Not in a List
- Boolean Expressions
- Exercise 5-1: Conditional Tests
- Exercise 5-2: More Conditional Tests
- if Statements
- Using if Statements with Lists
- Styling Your if Statements
- Summary
- Chapter 6: Dictionaries
- Chapter 7: User Input and while Loops
- Chapter 8: Functions
-
Chapter 9: Classes
- Creating and Using a Class
- Working with Classes and Instances
- Inheritance
-
Importing Classes
- Importing a Single Class
- Storing Multiple Classes in a Module
- Importing Multiple Classes from a Module
- Importing an Entire Module
- Importing All Classes from a Module
- Importing a Module into a Module
- Using Aliases
- Finding Your Own Workflow
- Exercise 9-10: Imported Restaurant
- Exercise 9-11: Imported Admin
- Exercise 9-12: Multiple Modules
- The Python Standard Library
- Styling Classes
- Summary
-
Chapter 10: Files and Exceptions
- Reading from a File
- Writing to a File
-
Exceptions
- Handling the ZeroDivisionError Exception
- Using try-except Blocks
- Using Exceptions to Prevent Crashes
- The else Block
- Handling the FileNotFoundError Exception
- Analyzing Text
- Working with Multiple Files
- Failing Silently
- Deciding Which Errors to Report
- Exercise 10-6: Addition
- Exercise 10-7: Addition Calculator
- Exercise 10-8: Cats and Dogs
- Exercise 10-9: Silent Cats and Dogs
- Exercise 10-10: Common Words
- Storing Data
- Summary
- Chapter 11: Testing Your Code
-
Part II: Projects
- Chapter 12: A Ship That Fires Bullets
- Chapter 13: Aliens!
-
Chapter 14: Scoring
- Adding the Play Button
- Leveling Up
-
Scoring
- Displaying the Score
- Making a Scoreboard
- Updating the Score as Aliens Are Shot Down
- Resetting the Score
- Making Sure to Score All Hits
- Increasing Point Values
- Rounding the Score
- High Scores
- Displaying the Level
- Displaying the Number of Ships
- Exercise 14-5: All-Time High Score
- Exercise 14-6: Refactoring
- Exercise 14-7: Expanding the Game
- Exercise 14-8: Sideways Shooter, Final Version
- Summary
-
Chapter 15: Generating Data
- Installing Matplotlib
-
Plotting a Simple Line Graph
- Changing the Label Type and Line Thickness
- Correcting the Plot
- Using Built-in Styles
- Plotting and Styling Individual Points with scatter()
- Plotting a Series of Points with scatter()
- Calculating Data Automatically
- Customizing Tick Labels
- Defining Custom Colors
- Using a Colormap
- Saving Your Plots Automatically
- Exercise 15-1: Cubes
- Exercise 15-2: Colored Cubes
- Random Walks
-
Rolling Dice with Plotly
- Installing Plotly
- Creating the Die Class
- Rolling the Die
- Analyzing the Results
- Making a Histogram
- Customizing the Plot
- Rolling Two Dice
- Further Customizations
- Rolling Dice of Different Sizes
- Saving Figures
- Exercise 15-6: Two D8s
- Exercise 15-7: Three Dice
- Exercise 15-8: Multiplication
- Exercise 15-9: Die Comprehensions
- Exercise 15-10: Practicing with Both Libraries
- Summary
-
Chapter 16: Downloading Data
-
The CSV File Format
- Parsing the CSV File Headers
- Printing the Headers and Their Positions
- Extracting and Reading Data
- Plotting Data in a Temperature Chart
- The datetime Module
- Plotting Dates
- Plotting a Longer Timeframe
- Plotting a Second Data Series
- Shading an Area in the Chart
- Error Checking
- Downloading Your Own Data
- Exercise 16-1: Sitka Rainfall
- Exercise 16-2: Sitka–Death Valley Comparison
- Exercise 16-3: San Francisco
- Exercise 16-4: Automatic Indexes
- Exercise 16-5: Explore
-
Mapping Global Datasets: GeoJSON Format
- Downloading Earthquake Data
- Examining GeoJSON Data
- Making a List of All Earthquakes
- Extracting Magnitudes
- Extracting Location Data
- Building a World Map
- Representing Magnitudes
- Customizing Marker Colors
- Other Color Scales
- Adding Hover Text
- Exercise 16-6: Refactoring
- Exercise 16-7: Automated Title
- Exercise 16-8: Recent Earthquakes
- Exercise 16-9: World Fires
- Summary
-
The CSV File Format
- Chapter 17: Working with APIs
- Chapter 18: Getting Started with Django
-
Chapter 19: User Accounts
- Allowing Users to Enter Data
- Setting Up User Accounts
-
Allowing Users to Own Their Data
- Restricting Access with @login_required
- Connecting Data to Certain Users
- Restricting Topics Access to Appropriate Users
- Protecting a User’s Topics
- Protecting the edit_entry Page
- Associating New Topics with the Current User
- Exercise 19-3: Refactoring
- Exercise 19-4: Protecting new_entry
- Exercise 19-5: Protected Blog
- Summary
-
Chapter 20: Styling and Deploying an App
- Styling Learning Log
-
Deploying Learning Log
- Making a Platform.sh Account
- Installing the Platform.sh CLI
- Installing platformshconfig
- Creating a requirements.txt File
- Additional Deployment Requirements
- Adding Configuration Files
- Modifying settings.py for Platform.sh
- Using Git to Track the Project’s Files
- Creating a Project on Platform.sh
- Pushing to Platform.sh
- Viewing the Live Project
- Refining the Platform.sh Deployment
- Creating Custom Error Pages
- Ongoing Development
- Deleting a Project on Platform.sh
- Exercise 20-3: Live Blog
- Exercise 20-4: Extended Learning Log
- Summary
- Appendix A: Installation and Troubleshooting
- Appendix B: Text Editors and IDEs
- Appendix C: Getting Help
- Appendix D: Using Git for Version Control
- Appendix E: Troubleshooting Deployments
- Index
Product information
- Title: Python Crash Course, 3rd Edition
- Author(s):
- Release date: January 2023
- Publisher(s): No Starch Press
- ISBN: 9781718502703
You might also like
book
Head First Python, 3rd Edition
What will you learn from this book? Want to learn the Python language without slogging your …
book
Automate the Boring Stuff with Python, 2nd Edition
If you’ve ever spent hours renaming files or updating hundreds of spreadsheet cells, you know how …
book
Head First Python, 2nd Edition
Want to learn the Python language without slogging your way through how-to manuals? With Head First …
book
Introducing Python, 2nd Edition
Easy to understand and fun to read, this updated edition of Introducing Python is ideal for …