Reputation:
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?
Upvotes: 2
Views: 1049
Reputation: 44354
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="")
Upvotes: 2
Reputation: 3244
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 :)
Upvotes: 0