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?

10th Jun 2019, 7:00 PM
Магомед Акуев
Магомед Акуев - avatar
4 Antworten
+ 7
m3 isn't a string type, but a class instance. It has a string representation that can be called with str() (or repr())
10th Jun 2019, 7:52 PM
Anna
Anna - avatar
+ 12
I thought firstly noncense is a Python component
10th Jun 2019, 7:55 PM
Bohdan Sakovych
Bohdan Sakovych - avatar
+ 3
print("my " + str(m3))
10th Jun 2019, 7:35 PM
Anna
Anna - avatar
0
i now, but why it is necessary to write: str (m3)), if just already (m3) is string type??
10th Jun 2019, 7:50 PM
Магомед Акуев
Магомед Акуев - avatar