Object
Object
Physical existence of a class is nothing but object. We can create any number of
objects for a class.
Syntax to create object: referencevariable = classname()
Example: s = Student()
What is Reference Variable:
The variable which can be used to refer object is called reference variable.
By using reference variable, we can access properties and methods of object.
Program: Write a Python program to create a Student class and Creates an object to
it. Call the
method talk() to display student details
1) class Student:
2)
3) def __init__(self,name,rollno,marks):
4) self.name=name
5) self.rollno=rollno
6) self.marks=marks
7)
8) def talk(self):
9) print("Hello My Name is:",self.name)
10) print("My Rollno is:",self.rollno)
11) print("My Marks are:",self.marks)
12)
13) s1=Student("amol",101,80)
14) s1.talk()