Book description
Python Crash Course is a fast-paced, thorough introduction to programming with Python that will have you writing programs, solving problems, and making things that work in no time.
In the first half of the book, you'll learn about basic programming concepts, such as lists, dictionaries, classes, and loops, and practice writing clean and readable code with exercises for each topic. You'll also learn how to make your programs interactive and how to test your code safely before adding it to a project. In the second half of the book, you'll put your new knowledge into practice with three substantial projects: a Space Invaders-inspired arcade game, data visualizations with Python's super-handy libraries, and a simple web app you can deploy online.
As you work through Python Crash Course, you'll learn how to:
- Use powerful Python libraries and tools, including matplotlib, NumPy, and Pygal
- Make 2D games that respond to keypresses and mouse clicks, and that grow more difficult as the game progresses
- Work with data to generate interactive visualizations
- Create and customize simple web apps and deploy them safely online
- Deal with mistakes and errors so you can solve your own programming problems
If you've been thinking seriously about digging into programming, Python Crash Course will get you up to speed and have you writing real programs fast. Why wait any longer? Start your engines and code!
Publisher resources
Table of contents
- Cover Page
- Title Page
- Copyright Page
- About the Author
- About the Technical Reviewer
- Brief Contents
- Contents in Detail
- 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
- Combining or Concatenating Strings
- Adding Whitespace to Strings with Tabs or Newlines
- Stripping Whitespace
- Avoiding Syntax Errors with Strings
- Printing in Python 2
- 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
- Numbers
- Comments
- The Zen of Python
- Summary
-
Chapter 3: Introducing Lists
- What Is a List?
- Changing, Adding, and Removing Elements
- Organizing a List
- Avoiding Index Errors When Working with Lists
- Summary
-
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
- The __init__() Method for a Child Class
- Inheritance in Python 2.7
- Defining Attributes and Methods for the Child Class
- Overriding Methods from the Parent Class
- Instances as Attributes
- Modeling Real-World Objects
- Exercise 9-6: Ice Cream Stand
- Exercise 9-7: Admin
- Exercise 9-8: Privileges
- Exercise 9-9: Battery Upgrade
-
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
- 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
-
Project 1: Alien Invasion
- 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
- Making Sure to Score All Hits
- Increasing Point Values
- Rounding the Score
- High Scores
- Displaying the Level
- Displaying the Number of Ships
- Exercise 14-4: All-Time High Score
- Exercise 14-5: Refactoring
- Exercise 14-6: Expanding Alien Invasion
- Summary
-
Project 2: Data Visualization
-
Chapter 15: Generating Data
- Installing matplotlib
-
Plotting a Simple Line Graph
- Changing the Label Type and Graph Thickness
- Correcting the Plot
- Plotting and Styling Individual Points with scatter()
- Plotting a Series of Points with scatter()
- Calculating Data Automatically
- Removing Outlines from Data Points
- Defining Custom Colors
- Using a Colormap
- Saving Your Plots Automatically
- Exercise 15-1: Cubes
- Exercise 15-2: Colored Cubes
-
Random Walks
- Creating the RandomWalk() Class
- Choosing Directions
- Plotting the Random Walk
- Generating Multiple Random Walks
- Styling the Walk
- Coloring the Points
- Plotting the Starting and Ending Points
- Cleaning Up the Axes
- Adding Plot Points
- Altering the Size to Fill the Screen
- Exercise 15-3: Molecular Motion
- Exercise 15-4: Modified Random Walks
- Exercise 15-5: Refactoring
-
Rolling Dice with Pygal
- Installing Pygal
- The Pygal Gallery
- Creating the Die Class
- Rolling the Die
- Analyzing the Results
- Making a Histogram
- Rolling Two Dice
- Rolling Dice of Different Sizes
- Exercise 15-6: Automatic Labels
- Exercise 15-7: Two D8s
- Exercise 15-8: Three Dice
- Exercise 15-9: Multiplication
- 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
- Exercise 16-1: San Francisco
- Exercise 16-2: Sitka-Death Valley Comparison
- Exercise 16-3: Rainfall
- Exercise 16-4: Explore
-
Mapping Global Data Sets: JSON Format
- Downloading World Population Data
- Extracting Relevant Data
- Converting Strings into Numerical Values
- Obtaining Two-Digit Country Codes
- Building a World Map
- Plotting Numerical Data on a World Map
- Plotting a Complete Population Map
- Grouping Countries by Population
- Styling World Maps in Pygal
- Lightening the Color Theme
- Exercise 16-5: All Countries
- Exercise 16-6: Gross Domestic Product
- Exercise 16-7: Choose Your Own Data
- Exercise 16-8: Testing the country_codes Module
- Summary
-
The CSV File Format
- Chapter 17: Working with APIs
-
Chapter 15: Generating Data
-
Project 3: Web Applications
-
Chapter 18: Getting Started with Django
- Setting Up a Project
- Starting an App
- Making Pages: The Learning Log Home Page
- Building Additional Pages
- Summary
-
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 Heroku Account
- Installing the Heroku Toolbelt
- Installing Required Packages
- Creating a Packages List with a requirements.txt File
- Specifying the Python Runtime
- Modifying settings.py for Heroku
- Making a Procfile to Start Processes
- Modifying wsgi.py for Heroku
- Making a Directory for Static Files
- Using the gunicorn Server Locally
- Using Git to Track the Project’s Files
- Pushing to Heroku
- Setting Up the Database on Heroku
- Refining the Heroku Deployment
- Securing the Live Project
- Committing and Pushing Changes
- Creating Custom Error Pages
- Ongoing Development
- The SECRET_KEY Setting
- Deleting a Project on Heroku
- Exercise 20-3: Live Blog
- Exercise 20-4: More 404s
- Exercise 20-5: Extended Learning Log
- Summary
-
Chapter 18: Getting Started with Django
- Afterword
- Appendix A: Installing Python
- Appendix B: Text Editors
- Appendix C: Getting Help
- Appendix D: Using Git for Version Control
- Index
- Resources
Product information
- Title: Python Crash Course
- Author(s):
- Release date: November 2015
- Publisher(s): No Starch Press
- ISBN: 9781593276034
You might also like
book
Python Crash Course, 2nd Edition
This is the second edition of the best selling Python book in the world. Python Crash …
video
Introduction to Python: Learn How to Program Today with Python
7+ Hours of Video Instruction Overview Python is a great, beginner-friendly programming language because it was …
book
Python Crash Course, 3rd Edition
Python Crash Course is the world's best-selling guide to the Python guide programming language, with over …
video
Practical Python: Learn Python Basics Step by Step - Python 3
Python is one of the most popular programming languages and gives a lot of scope and …