-6

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?

TeeJay
  • 5
  • 4
  • Possible duplicate of [Print multiple arguments in Python](https://stackoverflow.com/questions/15286401/print-multiple-arguments-in-python) – pault Aug 17 '18 at 14:47

2 Answers2

4

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
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
Laurent H.
  • 6,316
  • 1
  • 18
  • 40