This article mainly introduces the implementation of Python to insert a character at a specified position in a string. It has certain reference value. Now I share it with you. Friends in need can refer to it
As shown below:
str_1='wo shi yi zhi da da niu/n'str_list=list(str_1) nPos=str_list.index('/') str_list.insert(nPos,',') str_2="".join(str_list) print(str_2)
Extract lines from the file and insert a comma at the end of the line.
Related recommendations:
Python implementation to confirm whether a string contains an instance of a specified string
The above is the detailed content of Python implements inserting a character at a specified position in a string. For more information, please follow other related articles on the PHP Chinese website!