本站改版新增arduino频道
移除字符串中的指定位置字符
test_str = "Runoob"
# 输出原始字符串
print ("原始字符串为 : " + test_str)
# 移除第三个字符 n
new_str = ""
for i in range(0, len(test_str)):
if i != 2:
new_str = new_str + test_str[i]
print ("字符串移除后为 : " + new_str)参考方法: test_str = "Runoob" new_str = test_str.replace(test_str[3], "", 1) print(new_str)
参考方法: str = 'Runoob' ''' @param str 原字符串 @paramnum 要移除的位置 @return 移除后的字符串 ''' def ff(str,num): return str[:num] + str[num+1:]; print(ff(str,2)); print(ff(str,4));
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0093090534210205 seconds