Python 删除数字前后的空格

Python 删除数字前后的空格,python,Python,这是密码 for x in range(1, 30): print"www.interpol.com/file/",x,'/en' 它打印了这个 www.interpol.com/file/ 1 /en www.interpol.com/file/ 2 /en www.interpol.com/file/ 3 /en 但是我想去掉空格,得到这样的结果 www.interpol.com/file/1/en www.interpol.com/file/2/en www.interpol.

这是密码

for x in range(1, 30):
    print"www.interpol.com/file/",x,'/en'
它打印了这个

www.interpol.com/file/ 1 /en
www.interpol.com/file/ 2 /en
www.interpol.com/file/ 3 /en
但是我想去掉空格,得到这样的结果

www.interpol.com/file/1/en
www.interpol.com/file/2/en
www.interpol.com/file/3/en
我想我们可以使用
/b
或像
'

如果他们想要这样的结果 成功了,谢谢。但我还有一个问题。 假设我希望结果是这样的

www.interpol.com/file/30/en
www.interpol.com/file/60/en
www.interpol.com/file/90/en
www.interpol.com/file/120/en
那怎么做呢? 这一准则起了作用:

> for x in range(1, 30):
>     print("www.interpol.com/file/{}/en".format(x))

您可以使用
+
并将
x
转换为
str
(我假设这是Python):


您可以使用
+
并将
x
转换为
str
(我假设这是Python):


使用字符串的
格式
方法:

for x in range(1, 30):
    print("www.interpol.com/file/{}/en".format(x))

使用字符串的
格式
方法:

for x in range(1, 30):
    print("www.interpol.com/file/{}/en".format(x))

在Python3中:

from __future__ import print_function
最简单的方法是使用
sep=''
标志:

for x in range(1, 30):
    print("www.interpol.com/file/",x,'/en', sep='')
在Python2中,您需要首先导入新的打印函数:

from __future__ import print_function

它自定义打印语句中项目之间的分隔符。

在Python3中:

from __future__ import print_function
最简单的方法是使用
sep=''
标志:

for x in range(1, 30):
    print("www.interpol.com/file/",x,'/en', sep='')
在Python2中,您需要首先导入新的打印函数:

from __future__ import print_function

它定制了打印报表中项目之间的分隔符。

哈哈哇,我甚至没有想到这一点。你说得对,我要说的是,editstr(x)不是强制转换,而是创建一个值为x的str类型。将创建一个新对象。Casting告诉编译器内存中的数据将被视为某种类型。哈哈,哇,我甚至没有想到这一点。你说得对,我要说的是,editstr(x)不是强制转换,而是创建一个值为x的str类型。将创建一个新对象。强制转换是告诉编译器内存中的数据将被视为特定类型。您尝试过吗?发生了什么事?你是说(30、121、30)范围内的x的
?第三个关键字参数是步长,121,因为终点是非包容性的。您试过了吗?发生了什么事?你是说(30、121、30)范围内的x的
?第三个关键字参数是步长,121,因为结尾是非包容性的。在Python2true中,我认为Python3requires
from\uuuuuu future\uuuuu import print\u函数
在Python2true中,我认为Python3requires
from\uuuu future\uuu import print\u函数
,谢谢。但我还有一个问题。假设我希望结果类似于www.interpol.com/file/30/en www.interpol.com/file/60/en www.interpol.com/file/90/en,那么该怎么做呢?在Python 3中(或者Python 2中,如果您将
from uuuu future\uuuuuuu import print_函数
放在文件顶部),您可以执行
打印(“www.interpol.com/file/{}/en.format(x),end=”“)
要在python2中用空格替换换行符,可以在最后一个元素后添加
。用逗号结束print语句会忽略换行符,谢谢。但我还有一个问题。假设我希望结果类似于www.interpol.com/file/30/en www.interpol.com/file/60/en www.interpol.com/file/90/en,那么该怎么做呢?在Python 3中(或者Python 2中,如果您将
from uuuu future\uuuuuuu import print_函数
放在文件顶部),您可以执行
打印(“www.interpol.com/file/{}/en.format(x),end=”“)
要在python2中用空格替换换行符,可以在最后一个元素后添加
。以逗号结束print语句会忽略换行符