小编Mar*_*ıos的帖子

替换有时加倍的字符的单个实例

我有一个字符串,每个字符由管道字符(包括"|"s本身)分隔,例如:

"f|u|n|n|y||b|o|y||a||c|a|t"
Run Code Online (Sandbox Code Playgroud)

我想替换所有"|"不是"|"没有的东西,以获得结果:

"funny|boy|a|cat"
Run Code Online (Sandbox Code Playgroud)

我尝试过使用mytext.replace("|", ""),但这会删除所有内容,并且会产生一个长话.

python regex string replace

20
推荐指数
6
解决办法
3419
查看次数

如何将一串字母变成整数?

具体来说,我正在说一个用户输入的字,相当于一个数字(用户不知道).

我的代码:

animal = raw_input( > )  #and a user inputs cat
dog = 30 
cat = 10
frog = 5
print 10 + int(animal) #with the hope that will output 20
Run Code Online (Sandbox Code Playgroud)

不知道怎么做..

python python-2.7

3
推荐指数
1
解决办法
116
查看次数

标签 统计

python ×2

python-2.7 ×1

regex ×1

replace ×1

string ×1