I have a code like this.
print (' ', totalh, totalt, totalo)
and I want the integer of totalh
to be 2 2
instead of 22
with a space in-between the integers. How do I go about doing it?
I have a code like this.
print (' ', totalh, totalt, totalo)
and I want the integer of totalh
to be 2 2
instead of 22
with a space in-between the integers. How do I go about doing it?
Convert it to a string which is an iterable and can be an argument to " ".join
.
totalh = 22
print(" ".join(str(totalh)))
Output:
2 2
I suggest you this simple way: first convert totalh
into a string with each digit being a character, then use " ".join()
to insert a space between each digit:
totalh = 22
print(" ".join(str(totalh))) #2 2