所以標題解釋了它的大部分。我開始研究Objective-C for iOS,並且我還沒有發現是否有方法使用translate() - 就像在Objective C中一樣。如何在Python中使用目標c中的str.translate()方法?
這是我在Python中它:程序
#!/usr/bin/python
from string import maketrans # Required to call maketrans function.
intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)
str = "this is string example....wow!!!";
print str.translate(trantab);
輸出:
th3s 3S str3ng 2x1mpl2 .... w4w!
'str'是Python中的內建名稱;不要覆蓋它。 – jfs
他的例子直接來自這裏:http://www.tutorialspoint.com/python/string_translate.htm。我也假設他知道它是基於標題內置的。 – OozeMeister