jb51.txt

welcome to jb51.net
text I love you very much

python

 coding: UTF-8 code # -*- -*- meet the 'spaces' def line delblankline (infile, outfile): infopen = open (infile,'r', encoding=, UTF-8) outfopen = open (outfile,'w', encoding=, UTF-8 "DB = (infopen.read) (db.replace) outfopen.write ('n' ')) infopen.close (outfopen.close) (delblankline) (" jb51.txt "," o3.txt ") 

renderings

" src= "//files.jb51.net/file_images/article/201803/20180319205952.png" >

is mainly used in the replace function of

Python3 replace (

) method described (replace) the string old (string replaced new (old) A new string), if the third parameter Max is specified, the replacement is not more than max times.

syntax
replace () method syntax:

str.replace (old, new[, max])

parameter
-- the substring that will be replaced.
new - a new string that is used to replace the old substring.
Max -- the optional string is replaced by no more than max times
return value.
returns the new string generated by the old in the string (old string) instead of new (new string). If the third parameter Max is specified, then the replacement is no more than max times.

examples of
following example shows (replace) function is used:

 /usr/bin/python3 STR = "#! Welcome to visit the www.jb51.net print script" ("the old script home address:" STR "(print) script home new address:" str.replace ("jb51.net", "jbzj.com" STR)) = "this is string example....wow!!!" (print str.replace ("is", "was", 3)) 
above example output results are as follows:

script home address: welcome to visit the old script home http://www.jb51.net
script home new address: welcome to visit the home of http://www.jbzj.com
thwas script was string example....wow!!!


This concludes the body part

This paper fixed link:http://www.script-home.com/python-replace-the-space-in-the-text-as-a-line-of-line.html | Script Home | +Copy Link

Article reprint please specify:Python replace the space in the text as a line of line | Script Home

You may also be interested in these articles!