Python 移除字串中的指定位置字元
給定一個字串,然後移除制定位置的字元:
實例
test_str = "zaixian"
# 輸出原始字串
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)
# 輸出原始字串
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)
執行以上代碼,輸出結果為:
原始字串為 : zaixian 字串移除後為 : Ruoob