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

不言
Release: 2018-05-02 14:07:47
Original
11645 people have browsed it

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!