Select true statements about the __repr__() method. (select three)
Select true statements about the __repr__()
method. (select three)
a. The __repr__()
method is called when the repr()
function is called.
b. The __repr__()
method is always called when the str()
function is called.
c. The __repr__()
method returns the formal representation of the object as a string.
d. If possible, the returned string should be a valid Python expression that can be used to reconstruct the object.
a. The __repr__()
method is called when the repr()
function is called.
c. The __repr__()
method returns the formal representation of the object as a string.
d. If possible, the returned string should be a valid Python expression that can be used to reconstruct the object.
Explanation:
object.__repr__(self)
– called by the repr()
built-in function to compute the “official” string representation of an object. If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment).