Python Forum

Full Version: Doubt with int and str
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
x = 4
print ('x =' , x)

and
x= 4
print ('x =', str(x))

give me the same output. Why do I have to convert int to str?
In that context you don't, in other contexts you do. The print function automatically converts all of it's arguments to string. The format method of strings does that too, and gives you all sorts of options for how to show the integer. But the join method of strings expects a list of strings, and does not convert anything. So if you give it a list of integers it will choke.