2

My code is the following:

a = 60

print(a, ": string of text")

this prints "60 : string of text"

I would like it to print "60: String of text" without the space after the 60 if that makes sense

any ideas?

1
  • print("{}: string of text".format(a)) Commented Jun 14, 2016 at 9:17

3 Answers 3

2

There are several ways to remove the space delimiter. Fortunately print() only inserts a space between fields by default. From the print() doc:

"sep: string inserted between values, default a space."

So my preferred way would be to use an empty string:

print(a, ": string of text", sep="")
Sign up to request clarification or add additional context in comments.

Comments

0

print("{}: string of text".format(a))

Comments

0

if you use print(... , ... , ...) the , will always insert a space.

you can bypass that if you just concatenate them with

print(str(a) + ": string of text") 

(the str(..) is needed because a is a number) or you can use placeholders like so

print("%d: string of text" % a)

.. where %d stands for a digit. if you want a string, use %s

hope this helps :)

Comments