You are previewing Learn Python the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code, Third Edition, Video-Enhanced Edition.
O'Reilly logo
Learn Python the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code, Third Edition, Video-Enhanced Edition

Book Description

The Publisher regrets that the DVD content for this title cannot be made available Online.

You Will Learn Python!

Zed Shaw has perfected the world's best system for learning Python. Follow it and you will succeed-just like the hundreds of thousands of beginners Zed has taught to date! You bring the discipline, commitment, and persistence; the author supplies everything else.

In Learn Python the Hard Way, Third Edition, you'll learn Python by working through 52 brilliantly crafted exercises. Read them. Type their code precisely. (No copying and pasting!) Fix your mistakes. Watch the programs run. As you do, you'll learn how software works; what good programs look like; how to read, write, and think about code; and how to find and fix your mistakes using tricks professional programmers use. Most importantly, you'll learn the following, which you need to start writing excellent Python software of your own:

  • Installing a complete Python environment

  • Organizing and writing code

  • Basic mathematics

  • Variables

  • Strings and text

  • Interacting with users

  • Working with files

  • Looping and logic

  • Data structures using lists and dictionaries

  • Program design

  • Object-oriented programming

  • Inheritance and composition

  • Modules, classes, and objects

  • Python packaging

  • Debugging

  • Automated testing

  • Basic game development

  • Basic web development

  • It'll be hard at first. But soon, you'll just get it-and that will feel great!

    This tutorial will reward you for every minute you put into it. Soon, you'll know one of the world's most powerful, popular programming languages. You'll be a Python programmer.

    Table of Contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Contents
    5. Preface
      1. Acknowledgments
      2. The Hard Way Is Easier
      3. Do Not Copy-Paste
      4. A Note on Practice and Persistence
      5. A Warning for the Smarties
    6. Exercise 0. The Setup
      1. Mac OSX
      2. Windows
      3. Linux
      4. Warnings for Beginners
    7. Exercise 1. A Good First Program
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    8. Exercise 2. Comments and Pound Characters
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    9. Exercise 3. Numbers and Math
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    10. Exercise 4. Variables and Names
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    11. Exercise 5. More Variables and Printing
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    12. Exercise 6. Strings and Text
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    13. Exercise 7. More Printing
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    14. Exercise 8. Printing, Printing
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    15. Exercise 9. Printing, Printing, Printing
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    16. Exercise 10. What Was That?
      1. What You Should See
      2. Escape Sequences
      3. Study Drills
      4. Common Student Questions
    17. Exercise 11. Asking Questions
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    18. Exercise 12. Prompting People
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    19. Exercise 13. Parameters, Unpacking, Variables
      1. Hold Up! Features Have Another Name
      2. What You Should See
      3. Study Drills
      4. Common Student Questions
    20. Exercise 14. Prompting and Passing
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    21. Exercise 15. Reading Files
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    22. Exercise 16. Reading and Writing Files
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    23. Exercise 17. More Files
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    24. Exercise 18. Names, Variables, Code, Functions
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    25. Exercise 19. Functions and Variables
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    26. Exercise 20. Functions and Files
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    27. Exercise 21. Functions Can Return Something
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    28. Exercise 22. What Do You Know So Far?
      1. What You Are Learning
    29. Exercise 23. Read Some Code
    30. Exercise 24. More Practice
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    31. Exercise 25. Even More Practice
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    32. Exercise 26. Congratulations, Take a Test!
      1. Common Student Questions
    33. Exercise 27. Memorizing Logic
      1. The Truth Terms
      2. The Truth Tables
      3. Common Student Questions
    34. Exercise 28. Boolean Practice
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    35. Exercise 29. What If
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    36. Exercise 30. Else and If
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    37. Exercise 31. Making Decisions
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    38. Exercise 32. Loops and Lists
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    39. Exercise 33. While-Loops
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    40. Exercise 34. Accessing Elements of Lists
      1. Study Drills
    41. Exercise 35. Branches and Functions
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    42. Exercise 36. Designing and Debugging
      1. Rules for If-Statements
      2. Rules for Loops
      3. Tips for Debugging
      4. Homework
    43. Exercise 37. Symbol Review
      1. Keywords
      2. Data Types
      3. String Escape Sequences
      4. String Formats
      5. Operators
      6. Reading Code
      7. Study Drills
      8. Common Student Questions
    44. Exercise 38. Doing Things to Lists
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    45. Exercise 39. Dictionaries, Oh Lovely Dictionaries
      1. What You Should See
      2. Study Drills
      3. Common Student Questions
    46. Exercise 40. Modules, Classes, and Objects
      1. Modules Are Like Dictionaries
      2. What You Should See
      3. Study Drills
      4. Common Student Questions
    47. Exercise 41. Learning to Speak Object Oriented
      1. Word Drills
      2. Phrase Drills
      3. Combined Drills
      4. A Reading Test
      5. Practice English to Code
      6. Reading More Code
      7. Common Student Questions
    48. Exercise 42. Is-A, Has-A, Objects, and Classes
      1. How This Looks in Code
      2. About class Name(object)
      3. Study Drills
      4. Common Student Questions
    49. Exercise 43. Basic Object-Oriented Analysis and Design
      1. The Analysis of a Simple Game Engine
      2. Top Down vs. Bottom Up
      3. The Code for “Gothons from Planet Percal #25”
      4. What You Should See
      5. Study Drills
      6. Common Student Questions
    50. Exercise 44. Inheritance vs. Composition
      1. What is Inheritance?
      2. The Reason for super()
      3. Composition
      4. When to Use Inheritance or Composition
      5. Study Drills
      6. Common Student Questions
    51. Exercise 45. You Make a Game
      1. Evaluating Your Game
      2. Function Style
      3. Class Style
      4. Code Style
      5. Good Comments
      6. Evaluate Your Game
    52. Exercise 46. A Project Skeleton
      1. Installing Python Packages
      2. Creating the Skeleton Project Directory
      3. Testing Your Setup
      4. Using the Skeleton
      5. Required Quiz
      6. Common Student Questions
    53. Exercise 47. Automated Testing
      1. Writing a Test Case
      2. Testing Guidelines
      3. What You Should See
      4. Study Drills
      5. Common Student Questions
    54. Exercise 48. Advanced User Input
      1. Our Game Lexicon
      2. What You Should Test
      3. Design Hints
      4. Study Drills
      5. Common Student Questions
    55. Exercise 49. Making Sentences
      1. Match and Peek
      2. The Sentence Grammar
      3. A Word on Exceptions
      4. What You Should Test
      5. Study Drills
      6. Common Student Questions
    56. Exercise 50. Your First Website
      1. Installing lpthw.web
      2. Make a Simple “Hello World” Project
      3. What’s Going On?
      4. Fixing Errors
      5. Create Basic Templates
      6. Study Drills
      7. Common Student Questions
    57. Exercise 51. Getting Input from a Browser
      1. How the Web Works
      2. How Forms Work
      3. Creating HTML Forms
      4. Creating a Layout Template
      5. Writing Automated Tests for Forms
      6. Study Drills
      7. Common Student Questions
    58. Exercise 52. The Start of Your Web Game
      1. Refactoring the Exercise 43 Game
      2. Sessions and Tracking Users
      3. Creating an Engine
      4. Your Final Exam
      5. Common Student Questions
    59. Next Steps
      1. How to Learn Any Programming Language
    60. Advice from an Old Programmer
    61. Appendix. Command Line Crash Course
      1. Introduction: Shut Up and Shell
      2. Exercise 1: The Setup
      3. Exercise 2: Paths, Folders, Directories (pwd)
      4. Exercise 3: If You Get Lost
      5. Exercise 4: Make a Directory (mkdir)
      6. Exercise 5: Change Directory (cd)
      7. Exercise 6: List Directory (ls)
      8. Exercise 7: Remove Directory (rmdir)
      9. Exercise 8: Move Around (pushd, popd)
      10. Exercise 9: Make Empty Files (Touch, New-Item)
      11. Exercise 10: Copy a File (cp)
      12. Exercise 11: Move a File (mv)
      13. Exercise 12: View a File (less, MORE)
      14. Exercise 13: Stream a File (cat)
      15. Exercise 14: Remove a File (rm)
      16. Exercise 15: Exit Your Terminal (exit)
      17. Command Line Next Steps
    62. Index
    63. Where Are the Companion Content Files?