Science, asked by shravankunhoos3995, 1 year ago

Python: What is the use of __repr__ and __init__ functions and when these two functions become mandatory ?

Answers

Answered by rajanki
0

Python __str__()

This method returns the string representation of the object. This method is called when print() or str() function is invoked on an object.

This method must return the String object. If we don’t implement __str__() function for a class, then built-in object implementation is used that actually calls __repr__() function.

Python __repr__()

Python __repr__() function returns the object representation. It could be any valid python expression such as tuple, dictionary, string etc.

This method is called when repr() function is invoked on the object, in that case, __repr__() function must return a String otherwise error will be thrown.

Answered by vikrantsoni
0
sorry bro it is very difficult u can run it what output will come
Similar questions