Home >Backend Development >Python Tutorial >Python implements inserting a character at a specified position in a string

Python implements inserting a character at a specified position in a string

不言
不言Original
2018-05-02 14:07:4711834browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn