简体   繁体   English

Python 用整数删除 output 中的空格

[英]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.我正在为此寻找解决方案,搜索并尝试了几个解决方案,但没有一个使用 python 3.8.5 处理 int 数据类型。

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?我需要怎么做才能使用字符串和 integer 变量删除空格?

Thx谢谢

You can use f strings, introduced in python 3.6.您可以使用在 python 3.6 中引入的 f 字符串。

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

try this line it's better试试这条线更好

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

also makes your code readable and more controllable也让你的代码更易读、更可控

Instead of using , you can use +您可以使用+ ,不是使用

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

or you can use str.format()或者你可以使用str.format()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM