The World Wide Web, restored to 800 pixels of glory.
GeezerVison is showing www.runoob.com — Python 移除字符串中的指定位置字符 | 菜鸟教程
Python3 实例
给定一个字符串,然后移除指定位置的字符:
执行以上代码,输出结果为:
原始字符串为 : Runoob 字符串移除后为 : Ruoob
LW
150***[email protected]
参考方法:
test_str = "Runoob" new_str = test_str.replace(test_str[3], "", 1) print(new_str)
陈某某
904***[email protected]
str = 'Runoob' ''' @param str 原字符串 @paramnum 要移除的位置 @return 移除后的字符串 ''' def ff(str,num): return str[:num] + str[num+1:]; print(ff(str,2)); print(ff(str,4));
取消