O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Idiot's Guides: Beginning Programming

Book Description

Basic computer programming can be intimidating to anyone who has ever attempted to write their first line of code. Idiot's Guides: Basic Programming takes the fear out of learning programming by teaching readers the basics of programming with Python, an open-source (free) environment which is considered one of the easiest languages to learn for beginners, Python has consistent syntax, a solid standardized library, and a simplicity that isn't always present in other languages. Readers will learn not only the "how" of programming but the "why" so that they not only know how to write code, but why that code works, and how it relates to other languages and forms of programming. Readers will learn how to program through simple projects that help them to learn how basic programming works, while encouraging them to be creative and enabling them to see the tangible results of their coding.

Table of Contents

  1. Cover
  2. Title Page
  3. Copyright Page
  4. Introduction
  5. Part 1: Background on Computers and Terminology
    1. 1 So You Want to Program Computers
      1. What Is a Computer, Really?
        1. Hardware
        2. Firmware
        3. The Operating System
        4. Application Programs
      2. What Do Programs Do?
        1. Types of Programs
        2. How Does a Computer Program Work?
        3. The Lifetime of a Program
      3. Thinking Like a Programmer
    2. 2 Programming with Python
      1. What Is Python?
      2. Installing Python on Your Computer
        1. Determining Your Operating System Version
        2. Downloading the Python Installer
        3. Running the Installer
      3. Finding All the Little Pieces
      4. The IDLE Programming Editor
      5. Using Packages to Augment Your Programming
      6. Miscellaneous Tools for Programmers
        1. Code Editor
        2. Debugger
        3. Profilers, Automation, and Extensions
    3. 3 Your First Python Program
      1. Never Mind All That, I Want to Do Something!
      2. Writing a Script in an Editor
        1. Creating a Place to Save Your Files
        2. Creating the Script
        3. Running the Script from the Command Prompt
      3. When Bad Things Happen to Good Programmers
  6. Part 2: Learning Python
    1. 4 Variables
      1. Variables Defined
      2. Variable Types
        1. Boolean Operators
        2. The Complex Data Type
        3. Decimals and Fractions
        4. Sequences
        5. Sets
        6. Dictionaries
        7. Classes
      3. Creating a Variable
      4. Finding and Looking at the Value of a Variable
      5. Finding the Type of a Variable
      6. Changing the Value or Type of a Variable
    2. 5 Conditional Programming
      1. Conditions and the if Statement
      2. Multiple Commands in an if Statement
      3. But What If It Isn’t Equal?
      4. The else Statement
      5. The elif Statement
      6. Nested if Statements
      7. Using if Statements with Lists
      8. A Slight Digression into IDLE
    3. 6 Loops
      1. Introducing Loops
      2. The while Loop
      3. Looping for Math
      4. The break and continue Statements
      5. Infinite Loops
      6. Looping Backward
      7. Nested while Loops
      8. The for Loop
      9. Descending Loops
      10. Nested for Loops
      11. The else Clause
      12. Printing List Indexes with Items
    4. 7 Arrays
      1. What Are Arrays?
      2. Creating an Array in Python
      3. Working with Individual Array Elements
      4. Arrays as Stacks
      5. Converting an Array to a List
      6. Removing Data from an Array
      7. Determining the Number of Elements in an Array
      8. Finding an Array Element
      9. Adding and Extending Arrays
      10. Adding New Elements to an Array
      11. Slicing Arrays and Other Sequences
      12. Multidimensional Lists
    5. 8 String Basics
      1. String Literals
      2. Escape Sequences
      3. Formatted Output
        1. Using the Tab Character
        2. Other Python Characters Used for Formatting
        3. The Formatted Data
      4. Converting Bases
    6. 9 The New Way of Strings
      1. New-Style Formatting
      2. Arguments and Positioning
        1. Default and Positional Ordering
        2. Ordering by Name
      3. Formatting Output
        1. Setting the Width
        2. Being Precise
        3. Justifying Your Existence
        4. Numeric Formatting for Floating-Point Numbers
        5. Dynamic Formatting
      4. Miscellaneous String Formatting Options
        1. Padding and Filling
        2. Slicing
  7. Part 3: Basic Programming Concepts
    1. 10 Functions
      1. What Is a Function?
        1. Reusing Code
        2. Encapsulation
      2. Determining a Function
        1. Defining a Function
        2. Designing a Function
      3. What Do You Know? What Don’t You Know?
      4. Coding by Comment
      5. Turning It into a Function
      6. Using the Function
      7. Yes, It’s a Function, but Is It a Good Function?
      8. Redesigning the Function
      9. Named Function Arguments
      10. A Word About Scope
        1. Where a Variable Starts and Stops Being Valid
        2. Global Variables
    2. 11 Does Anybody Really Know What Time It Is?
      1. Understanding How Computers Measure Time
      2. The Time Structure
      3. Printing a Calendar
      4. Converting Base Time to Local Time
      5. Formatting Dates
      6. Using Your Own Dates
      7. Dates and Math
        1. Passing the End of the Year
        2. Leap Years
      8. Working with Time
      9. Inputting and Parsing Dates and Times
      10. Working with Timers
    3. 12 Error Handling, or When Things Go Terribly Wrong
      1. Errors Defined
      2. Kinds of Information and Their Relation to Errors
      3. How Are Errors Propagated?
      4. Exceptions
        1. Handling Multiple Exceptions
        2. The else and finally Blocks
      5. Raising Exceptions
        1. Statement for Raising Exceptions
        2. When and When Not to Raise Exceptions
      6. Using Error Codes
      7. Dealing with Errors in Functions
        1. Throwing Exceptions
        2. Returning Error Codes
        3. Should You Use Error Codes or Exceptions in Functions?
      8. Type-Safe Conversions Using Exceptions
    4. 13 Files, Directories, and Other Things That Persist
      1. Persistent Storage
      2. Files
      3. Directories
      4. Creating Files
      5. Saving Data to Files
      6. Putting Data into Files
      7. Where Was That File Again?
      8. Reading Files
      9. Moving Around Files
      10. Finding and Identifying Files in a Directory
      11. Obtaining File Information
      12. Storing Preferences
    5. 14 Programming with Class(es)
      1. The Principles of Object-Oriented Programming
        1. Encapsulation
        2. Abstraction
        3. Inheritance
        4. Polymorphism
      2. Classes and Objects
      3. The Life and Times of a Class Object
        1. Constructors and Destructors
        2. How Class Objects Work
      4. Class Variable Accessibility
      5. Deriving Child Classes
      6. Overriding Functionality in a Child Class
      7. Multiple Inheritance
      8. Embedding Classes
      9. Dynamic Attributes
  8. Part 4: Working with the Python Environment
    1. 15 Graphics and Python
      1. What Are Turtle Graphics?
      2. How Do Turtle Graphics Work?
      3. Creating a Simple Graphic Display
      4. Creating a More Random Graphic Display
      5. Filling in Shapes with Color
      6. Adding Text
      7. Drawing Fractals
      8. Drawing Charts and Graphs
  9. 16 Packages and Modules
    1. Reusing Code
      1. Why Write or Use It?
      2. What About New Code?
    2. Creating a Module
    3. What Else Can I Do with My Module?
      1. Specifying Data Values
      2. Getting Rid of the Clarifying Name
      3. Assigning Local Names to Modules
    4. Module Limitations and Issues
    5. Creating a Package
      1. Making a Directory
      2. Putting Files into the Directory
      3. Making a Constructor for the Package
      4. Associating the Package with Python
    6. What Is in a Package?
    7. How Do I Use the Function?
  10. 17 Designing Programs
    1. The Art of Program Design
      1. There’s No “Perfect” Program
      2. Program Design as a Whole
    2. Requirements for Program Design
      1. The Qualities of Requirements
      2. Why You Need Requirements
    3. Breaking Down Requirements
      1. How to Decompose a Requirement
      2. Requirement Paralysis
    4. Working with Users on Designing a Program
    5. The Layers of a Program
      1. Identifying Layers
      2. Why Separate the Layers?
    6. Designing a Complex Application
      1. Breaking Down Classes
      2. Defining the Classes at a High Level
      3. An Example of Software Decomposition
      4. Determining the Needed Functionality
    7. Final Thoughts on Design
  11. 18 Testing
    1. What Is Testing?
    2. Different Kinds of Testing
      1. Unit Testing
      2. Mock Testing
      3. Ad-Hoc Testing
      4. Regression Testing
      5. Integration Testing
      6. Load Testing
      7. Usability Testing
      8. Security Testing
      9. Acceptance Testing
    3. Examples of Testing
    4. What Does Testing Produce?
    5. Complex Testing
      1. Creating Test Scripts for Reuse
      2. Testing Classes
    6. Physical vs. Logical Errors
    7. When Have You Done Enough Testing?
  12. 19 The Python Debugger and Debugging
    1. What Is Debugging?
    2. How to Debug a Python Program
    3. Instrumenting Code to Be Debugged
    4. Moving Through the Code
    5. Stepping Line by Line Through the Code
    6. Examining Values in the Debugger
    7. Modifying Values in the Debugger
    8. Where Am I?
    9. Dealing with Functions
    10. Breakpoints
    11. Using the Debugger to Evaluate Functions
    12. Changing a Variable in the Debugger
    13. Exiting the Debugger
    14. Final Thoughts on Programming
  13. Appendixes
    1. A Glossary
    2. B Resources
  14. Index