Python Remove the Character at a Specified Position in a String
Given a string, remove the character at a specified position:
Example
test_str
=
"Runoob"
Print the original string
(
"The original string is : "
- test_str
)
Remove the third character n
new_str
=
""
for
i
in
range
(
0
,
len
(
test_str
)
)
:
if
i
!=
2
:
new_str
=
new_str + test_str
[
i
]
(
"After removal the string is : "
- new_str
)
The output of the code above is:
原始字符串为 : Runoob
字符串移除后为 : Ruoob
Python3 Examples