PyNotes
261 subscribers
125 photos
7 videos
1 file
60 links
**Code is communication**
admin: @Xojarbu
https://t.me/solutions_py for problem solutions
Download Telegram
#class #methods
Title: __repr__ with __str__


—When we call Class it is represented by __str__ method by default, if there is not __str__ method, __repr__() method will be called.
—The __repr__() method returns the code representation of an instance, The __str__() method converts the instance to a string

! A good example is provided above

source: "Python Cookbook:
#class #constructor
In python every class has a constructor, but its not required to explicitly define it.

the __init__() method is a constructor and is always called when an object is created.

There are two types of constructors:
Default constructor - a simple constructor which doesn’t accept any arguments.

Parameterized constructor - a constructor with arguments.

Source1, Source2