Introduction to Python


How to install Python on Linux
How to run a Python program
The basic of Python codes
Data expressions
Built-in functions in Python
Interactive input/output
Conditional statement for Python
Loop structure for Python
Creating your own functions
Python modules
Reading/writing files for Python
Error handling code
Object Oriented Programming (OOP)
Tkinter package for GNU programming

Object Oriented Programming (OOP)

Here is an example of the object oriented program for python. The method, __init__(), means to perform when being made an instance. (Note that you have to use an underscore twice.)
class Human(object):
   def __init__(self,name): #Object's variable
   def intro(self): #Object's method
     print "My name is %s" %

mike = Human("Mike")
don = Human("Don")

$ Mike
$ My name is Mike
$ My name is Don

Inheritance is an important concept for OOP. The following is a simple example of inheritance of the above code.
class Human(object):
   def __init__(self,name):
   def intro(self):
     print "My name is %s" %

class MetaHuman(Human):
   def think(self):
     print "%s is a philosopher..." %

mike = Human("Mike")
don = MetaHuman("Don")

$ My name is Mike
$ Don is a philosopher...

Back to Electronics Page

Back to Hiro's Physics Main