Intro to
Programming
with Python

Fall 2010
course
navigation

sep 21

chap 5 : exploring "objects" with a graphics API

This is usually a fun week ...

objects

Object oriented programming is a popular paradigm these days. It's not the only one, but it's an important one.
An "object" is a abstration chunk of data (a "thing") with actions (called "methods") it can perform.
A "class" is a kind of object. Example: Point, Circle, GraphWin
An "instance" is a specific object: Example: that red circle right there.
In python, creating an instance is done this way : p = Point(10, 20) # instance_variable = ClassName(argument1, arg2)
And once we have one, we can tell it do things like this: p.move(2, 3) # change position (x,y)=(10,20) to (12,23)
An "API" (Application Programmer's Interface) is a description of which sorts of objects you can create, and what methods they have.
All this is pretty abstract, so let's see a concrete example with the attached files.

graphics.py

See the resources or Zelle's book page for both (1) the file you'll need to run this stuff (put in in the same directory), and (2) the API of what you can do with it.
Stuff to play around with interactively class:
... and so on
Tic Tac Toe, anyone ?
http://cs.marlboro.edu/ courses/ fall2010/python/ notes/ sep_21
last modified Tuesday September 21 2010 2:13 am EDT

attachments [paper clip]

     name last modified size
   graphics.py Sep 21 2010 2:13 am 28.8kB    triangle.py Sep 21 2010 2:12 am 760B