Python Forum
Doubt with int and str
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Doubt with int and str
#1
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?
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020