Replacing instances of a character in a string

前端 未结 13 2678
谎友^
谎友^ 2020-11-22 07:19

This simple code that simply tries to replace semicolons (at i-specified postions) by colons does not work:

for i in range(0,len(line)):
     if (line[i]==\"         


        
13条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 07:39

    If you are replacing by an index value specified in variable 'n', then try the below:

    def missing_char(str, n):
     str=str.replace(str[n],":")
     return str
    

提交回复
热议问题