python逗号替换

zachary124 发布于 2013/07/29 11:46
阅读 1K+
收藏 0

urns =3591405660750899_195861,3575017561986231_195861

我想把上面的,号替换成其他字符,但是不成功,求帮助


urns = str(urns).replace(',',' OR ')

urns = str(urns).replace('\,',' OR ')

都不行,网上没找到有效的方法


加载中
0
nanlong
nanlong

urns = '3591405660750899_195861,3575017561986231_195861'
urns = urns.replace(',', '-')
print urns

>>>3591405660750899_195861-3575017561986231_195861

0
zachary124
zachary124

引用来自“Machine”的答案

urns = '3591405660750899_195861,3575017561986231_195861'
urns = urns.replace(',', '-')
print urns

>>>3591405660750899_195861-3575017561986231_195861

谢谢,我的原来是后面的替换有问题,有空格
0
zachary124
zachary124

引用来自“Machine”的答案

urns = '3591405660750899_195861,3575017561986231_195861'
urns = urns.replace(',', '-')
print urns

>>>3591405660750899_195861-3575017561986231_195861

刚学习python,请教一下,为什么我把逗号替换成" OR "(OR两边是空格),然后输出控制台什么都看不到,但是我用replace('195861',' OR '),也就是把数字替换成" OR "却可以呢,我现在是想实现replace(',',' OR ')这样的替换,有什么办法吗,谢谢
杨同学
杨同学
我试了一下,可以啊 >>> urns = '3591405660750899_195861,3575017561986231_195861' >>> urns = urns.replace(",", " OR ") >>> print urns 3591405660750899_195861 OR 3575017561986231_195861
0
zachary124
zachary124

引用来自“卸载防沉迷”的答案

引用来自“Machine”的答案

urns = '3591405660750899_195861,3575017561986231_195861'
urns = urns.replace(',', '-')
print urns

>>>3591405660750899_195861-3575017561986231_195861

刚学习python,请教一下,为什么我把逗号替换成" OR "(OR两边是空格),然后输出控制台什么都看不到,但是我用replace('195861',' OR '),也就是把数字替换成" OR "却可以呢,我现在是想实现replace(',',' OR ')这样的替换,有什么办法吗,谢谢
我找到原因了,因为我的字符串是从文件里面读出来的,所以数字不会被编码
返回顶部
顶部