加载中...

Python

  1. Home
  2. Computing & Technology
  3. Python

Basic Python

By Al Lukaszewski, About.com Guide to Python

This set of guides and tutorials is oriented to the person who has never programmed in Python before. There is also a special section for those who have never programmed before. If you are new to Python or computer programming in general, you are especially encouraged to use this group of tutorials as your starting point.

  1. Shell or File
  2. Data Types
  3. Operators
  4. Flow Control
  1. Syntax
  2. Data Structures
  3. Outside In
  4. Further On

Shell or File

Starting out, one quickly learns that there are two ways to program Python: in the Python shell or in a Python file. This section gives an overview of both. In the main, you will want to write your programs in a file using a text editor, but using the shell can be very helpful for trying out code.

Data Types

One of the first things to learn when programming is that not all data is created equal. Various types of data fit best into different-sized containers. This section introduces the various data types used in Python programming.

Operators

Data by itself is not very useful. Like adding two and two, you need to be able to do something with data. That doing is commonly called data processing. Even the most fundamental data processing requires operators, signs and symbols that tell the computer what to do to and with data. Here we take a look at the most common Python operators and how to use them.

Flow Control

Part of data processing is being able to switch an operator on and off according to the conditions of the data. Here we look at forming conditions and loops and how to use ranges as a shortcut for long, predictable series.

Syntax

Data types, operators, and flow control are just the beginning of Python programming. If you use them alone, you are liable to get a very unreadable program very quickly. Fortunately, Python has readability built into its syntax rules. Read this section to find out how.

Data Structures

Data types are just categories for kinds of data. Data structures, on the other hand, relate to how to create re-usable code. Re-usable code is easier to maintain and debug. Here is how to write functions and classes in Python.

Outside In

In general, computer programs do not realise their full effectiveness until they can read or write outside themselves. Being able to import modules from the Python Library allows the programmer to use pre-written code safely and predictably. Being able to read and write files to the local disk or to a network server half-a-world away is essential for a modern program. If you do either, however, you must be able to handle errors and exceptions because your program will inevitably see aberrant data in the "wild."

Further On

Having worked through the preceding seven parts of Basic Python, you are ready to delve into more advanced material. This section contains links and references to several Python resources that can help you both online and off.

Newsletters

Python

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.