Python regular/instance method code snippets

Posted by

 

Hello Coders,

We have discussed the python regular or instance methods on the Youtube channel. If you go through this, you will have a clear understanding of the regular or instance method, and also it will help to crack the interviews.

Here are the code snippets of the Videos Link here.

class Student:

    def __init__(self,name, roll):
        self.name = name
        self.roll = roll

    def display(self):
        print(f"name of the student: {self.name}, roll: {self.roll}")
student_1 = Student("anil",13)
student_1.display()

name of the student: anil, roll: 13

student_2 = Student("sanjay",15)

student_2.display()

name of the student: sanjay, roll: 15

student_1.display
<bound method Student.display of <__main__.Student object at 0x000001D575390130>>
student_2.display
<bound method Student.display of <__main__.Student object at 0x000001D577302E50>>
student_1.display is student_2.display
False

Leave a Reply

Your email address will not be published.