Python3 Remove Space From Print
I've got some simple python loop through a name to create a list of devices: for i in range(18): print('sfo-router',(i)) The problem is it prints with a space between the name and
Solution 1:
Change the sep
parameter so that print
doesn't implicitly insert a space:
for i in range(18):
print("sfo-router",(i), sep='')
Alternatively, you can convert your number to a string with str
and concatenate:
for i in range(18):
print("sfo-router" + str(i))
Outputs: (in both cases)
sfo-router0
sfo-router1
sfo-router2
sfo-router3
sfo-router4
sfo-router5
...
Solution 2:
Use format:
for i in range(18):
print("sfo-router{}".format(i))
Solution 3:
I'm new at python as well, and a quick google search did this one:
Just use str.replace()
:
string = 'hey man'string.replace(" ","")
# Stringis now 'heyman'
Post a Comment for "Python3 Remove Space From Print"