user3017714
user3017714

Reputation: 7

Python remove blank spaces in output with integers

I'm looking for a solution for this, searched and tried several ones, but none working with int datatypes, using python 3.8.5.

begin = 1
end = 273
print ("lines:", begin, "-", end)

result:

lines: 1 - 273

needed:

lines: 1-273

What do I need to do to remove the blank spaces using string and integer variables?

Thx

Upvotes: 0

Views: 1089

Answers (3)

Nick
Nick

Reputation: 21

Instead of using , you can use +

begin = 1
end = 273
print ("lines:", str(begin)+"-"+str(chunk1_end))

or you can use str.format()

begin = 1
end = 273
print ("lines: {}-{}".format(begin, chunk1_end))

Upvotes: 1

sebastianmarines
sebastianmarines

Reputation: 31

You can use f strings, introduced in python 3.6.

begin = 1
end = 273
print(f"lines: {begin}-{end}")

Upvotes: 3

Soufiane Afandi
Soufiane Afandi

Reputation: 21

try this line it's better

print(f"lines: {begin}-{chunk1_end}")

also makes your code readable and more controllable

Upvotes: 2

Related Questions