3
I observed that, in Python, when we have an object with the method __str__
, it is responsible for returning a string representing the object - or something like that.
Example:
from uuid import uuid4
uuid4().__str__()
The exit is:
36cdc126-9d4d-43f9-9ede-bef8e15b834c
However, the same is true with the call of str
passing this same object as parameter.
str(uuid4())
The exit is:
36cdc126-9d4d-43f9-9ede-bef8e15b834c
I have some questions about that:
Is there any difference between the method call
__str__
(my_object.__str__()
in relation to the finding ofstr
(str(my_object)
)?The method
__str__
is used by the functionstr
?Taking into account the good practices I should apply to the language, which of the two ways I should use to return the object as a string?
You use the
#
to represent my questions. You don’t think the>
would be better?– Wallace Maxters
Whatever. If you want to edit, feel free.
– Leonel Sanches da Silva
@Ciganomorrisonmendez I think you should review the formatting you do in your responses, the use of
#
makes sense in a longer response with subtitles, the current way creates visual pollution making it difficult to read. Think that your answer is like a document to be delivered to a client or a college professor, I’m not saying to follow ABNT standards, but this your current pattern of using#
not good.– Paulo
@Orion Honestly, I don’t see this visual pollution you’re talking about, but I can replace the signals, no problem.
– Leonel Sanches da Silva
Pow dude, don’t you see the pollution in this post? It’s polluted like hell!!
– Math