I'm sure some of you started studying Python after learning Ruby. And while studying Python, I think you may be wondering, "How do you write that method in Ruby in Python?" This time, it is the
Ruby =>The value you want to convert to a string.to_s Python => str(The value you want to convert to a string)
#For Ruby name = SampleUser name.to_s # "SampleUser" #For Python name = SampleUser str(name) # "SampleUser"
Quoted from @ shiracamus's comment (Thank you !!!)
Each object has a str and repr method. The str function (actually the str class) calls those methods appropriately, converts them into strings, and then converts them into character codes. Reference: https://docs.python.org/ja/3/library/stdtypes.html#str
>>> 123 .__str__() '123' >>> 3.14.__str__() '3.14' >>> None.__str__() 'None'