1. Home
  2. Computing & Technology
  3. Python

"Hello, World!": A Quick Tutorial on Python

By Al Lukaszewski, About.com

3 of 6

A Class Called Felicitations

From this, we can create a class called Felicitations:

class Felicitations(object):
     def __init__(self):
         self.felicitations = [ ]
     def addon(self, word):
          self.felicitations.append(word)
     def printme(self):
          greeting = string.join(self.felicitations[0:], "")
          print greeting

The class is based off of another type of object called 'object'. The first method is mandatory if you want the object to know anything about itself (instead of being a brainless mass of functions and variables; the class must have a way of referring to itself. The second method simply adds the value of word to the Felicitations object. Finally, this class has the ability to print itself via a method called 'printme'.

In Python, indentation is important. Every nested block of commands must be indented the same amount. Python has no other way to differentiate between nested and non-nested blocks of commands.

3 of 6

Explore Python

More from About.com

  1. Home
  2. Computing & Technology
  3. Python
  4. Beginning Python
  5. Python "Hello World" Tutorial - A Python Class Called Felicitations

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

All rights reserved.