Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Remove the Character at a Specified Position in a String

Python Remove the Character at a Specified Position in a String

Document Object Reference Manual Python3 Examples

Given a string, remove the character at a specified position:

Example

test_str

=

"Runoob"

 

Print the original string

print

(

"The original string is : "

)

 

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

]

print

(

"After removal the string is : "

)

The output of the code above is:

原始字符串为 : Runoob

字符串移除后为 : Ruoob

Document Object Reference Manual Python3 Examples