0
What a noncense ?
class Car: def __str__(self): return str (self. model) m3 = Car( ) m3.model = "bmw" ---------------------------------------- print (m3) >>output: bmw # "bmw" printed as a string print ("my_" + (m3)) >>output: TypeError must be str, not Car #Why this happens? # Why now operation: "my_" + "bmw" doesn't exist?
4 Respostas
+ 7
m3 isn't a string type, but a class instance. It has a string representation that can be called with str() (or repr())
+ 12
I thought firstly noncense is a Python component
+ 3
print("my " + str(m3))
0
i now, but why it is necessary to write: str (m3)), if just already (m3) is string type??