Python crash course : a hands-on, project-based introduction to programming [2nd edition] 9781593279295, 1593279299

Second edition of the best selling Python book in the world. A fast-paced, no-nonsense guide to programming in Python. T

4,837 984 5MB

English Pages 506 Year 2019

Report DMCA / Copyright

DOWNLOAD FILE

Python crash course : a hands-on, project-based introduction to programming [2nd edition]
 9781593279295, 1593279299

Table of contents :
Content: Intro
Brief Contents
Contents in Detail
Preface to the Second Edition
Acknowledgments
Introduction
Who Is This Book For?
What Can You Expect to Learn?
Online Resources
Why Python?
Part I: Basics
Chapter 1: Getting Started
Setting Up Your Programming Environment
Python Versions
Running Snippets of Python Code
About the Sublime Text Editor
Python on Different Operating Systems
Python on Windows
Python on macOS
Python on Linux
Running a Hello World Program
Configuring Sublime Text to Use the Correct Python Version
Running hello_world.py
Troubleshooting Running Python Programs from a TerminalOn Windows
On macOS and Linux
Summary
Chapter 2: Variables and Simple Data Types
What Really Happens When You Run hello_world.py
Variables
Naming and Using Variables
Avoiding Name Errors When Using Variables
Variables Are Labels
Strings
Changing Case in a String with Methods
Using Variables in Strings
Adding Whitespace to Strings with Tabs or Newlines
Stripping Whitespace
Avoiding Syntax Errors with Strings
Numbers
Integers
Floats
Integers and Floats
Underscores in Numbers
Multiple Assignment
Constants
Comments How Do You Write Comments?What Kind of Comments Should You Write?
The Zen of Python
Summary
Chapter 3: Introducing Lists
What Is a List?
Accessing Elements in a List
Index Positions Start at 0, Not 1
Using Individual Values from a List
Changing, Adding, and Removing Elements
Modifying Elements in a List
Adding Elements to a List
Removing Elements from a List
Organizing a List
Sorting a List Permanently with the sort() Method
Sorting a List Temporarily with the sorted() Function
Printing a List in Reverse Order
Finding the Length of a List Avoiding Index Errors When Working with ListsSummary
Chapter 4: Working with Lists
Looping Through an Entire List
A Closer Look at Looping
Doing More Work Within a for Loop
Doing Something After a for Loop
Avoiding Indentation Errors
Forgetting to Indent
Forgetting to Indent Additional Lines
Indenting Unnecessarily
Indenting Unnecessarily After the Loop
Forgetting the Colon
Making Numerical Lists
Using the range() Function
Using range() to Make a List of Numbers
Simple Statistics with a List of Numbers
List Comprehensions
Working with Part of a List
Slicing a List Looping Through a SliceCopying a List
Tuples
Defining a Tuple
Looping Through All Values in a Tuple
Writing over a Tuple
Styling Your Code
The Style Guide
Indentation
Line Length
Blank Lines
Other Style Guidelines
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
if Statements
Simple if Statements
if-else Statements

Polecaj historie