INSY 404 Lecture Slide - 3
INSY 404 Lecture Slide - 3
2. OBJECT CREATION
4. SELF ARGUMENT
5. TYPES OF CONSTRUCTORS
6. __INIT__ METHOD
7. QUESTION
In order to proceed with OOP in Python, one must first
suite of statements.
SYNTAX
class ClassName:
#Statement Suite
IMPORTANT NOTE:
1. The keyword “class” should be in lower case, while the class name
3. The body of the class starts on a new line, indented one tab from the
left.
class Employee:
id = 10110
name = “Sogun Dakwambo"
This illustration creates a Python class called Employee, which has two
fields (id and name) for employee id and employee name respectively.
ILLUSTRATION 2:
class Dog:
pass
This illustration creates a Python class called Dog. In this case, the
follows:
SYNTAX
1. In the syntax statement for creating an object, there may or may not
class Employee:
id = 10
name = "John"
emp = Employee()
emp.name=“Samuel”
This illustration creates a Python object called emp from the class
Employee. Note that emp object inherited the fields (attributes) of the
# Driver code
obj = Test()
obj.fun()
ILLUSTRATION 5:
2. Non- 3.
1. Default
Parameterized Parameterized
Constructor
Constructor Constructor
In Python, Constructors are implemented using __init__
method. It is run as soon as an object of a class is instantiated.
# A Sample class with init method (demo_init.py)
class Person:
# Sample Method
def greet_you(self):
print(‘Hello, my name is’, self.name)
p = Person(‘Salako’)
p.greet_you ()
CLASS ASSIGNMENT