Pages

Saturday, October 20, 2012

PY-01: Elements of a Python Program, Part 1

This post is intended to teach the basic, core elements of a Python program, so that a foundation is built upon which more advanced teaching can take place. As with most programming languages, learning Python can be a tedious process, so prepare for a ton of reading and videos (and, hopefully, blog posts ;D).


IDLE (Integrated Development Environment)

The first, and arguably the most important, element of our Python program is IDLE -- or Integrated Development Enviroment (yeah, we know -- it should be IDE!). This is the program which combines a text editor, a debugger (for finding issues in the code), and a shell (which interprets the code).

Objects

This may come as no shock to you, but everything in Python is an object, even the code itself. This is so that everything can be referenced and called by other pieces of code and objects, allowing for complicated integration of objects calling other objects. It really is marvelous.

Every object has a particular type, which determines the very things that object can do, and how it is handled. Such types include the scalar (indivisible type), nonscalar (divisible), Boolean (true/false), or None (self-explanatory!).

Expressions

Objects are inherently useless to programmers, since all they do is store data. While data is cool and all, it has to be strung together in expressions to truly harness their power. Expressions are sequences of objects and operators, much like sentences are sequences of words (this is intentionally convenient).

Variables

It would be hard to form legible expressions if objects didn't have custom-made names that we assigned them. A program might look more like a computer's instructions than a human's if they were all named "object0001," "object0002," etc. (or something like that).

This is where variables come in. Variables allow for the programmer (or program) to assign objects a particular name, that allows for the object to be called for use when the variable name of that object is called. This makes program look more like English than code, and allows for simpler programming.


This post is continued in PY-02, the next post on Python coding, where I will cover conditionals, straight-line programs, branching programs, loops, and a few commands that are almost necessary for any good program.

No comments:

Post a Comment