Python Programming - Simple One Using a Class and Method

by matt392 in Circuits > Software

890 Views, 8 Favorites, 0 Comments

Python Programming - Simple One Using a Class and Method

python-logo-master-v3-TM.png
# Basic program that creates a class and a method

# create a class called "Person"
class Person:
# Create method "hello"
# Note: must use 'self' in parameter list
def hello(self):
  print "Hello world!"
 
# create object "bob" of class "Person"
bob = Person()

# call method "hello" on object "bob"
bob.hello()