Tuesday, November 4, 2008

Chapter 6

Classes and objects are a major part of computer programming. In python, they serve as the same purpose as every other language out there. If you want to clarify a class, you need to type in the keyword, class. Lets make a class called Apartment.
class Apartment:

You must add a colon at the end of the statement. A common practice with Python programmers is to capitalize the first letter of their class. When you have more than one word for a class then you capitalize the first letter of the next word.

You can create objects very easily in Python. Once you create a class you can then create an object. This is done by usually assigning a letter to a class and assigning it blank parameters.

class Apartment:
r = Apartment()
(Note that we indent. As you work through as class, you must indent for it to work. Objects or methods cannot be underneath directly under your class. )

The primary setup of creating a class with method and objects go by.

Class
Methods
.
.
.
Objects

We learned earlier how to create methods by writing def in front of the method.
In order to get a full understanding of this chapter please look at the book. You must read the example in the book because it lays everything out. The example is really good if you forget how to do things we learned in earlier chapters.

No comments: