Copy Code code as follows:
Mulline = "" "Hello!!!
Wellcome to Python ' s world!
There are a lot of interesting things!
Enjoy yourself. Thank you! "" "
print '. Join (Mulline.splitlines ())
print '------------'
print '. Join (Mulline.splitlines (True))
Output results:
Hello!!! Wellcome to Python ' s world! There are a lot of interesting things! Enjoy yourself. Thank you!
------------
Hello!!!
Wellcome to Python ' s world!
There are a lot of interesting things!
Enjoy yourself. Thank you!
With this function, it is very convenient to write some of the functions of paragraph processing, such as processing indentation and other methods. As in the cookbook book Example:
Copy Code code as follows:
def addspaces (S, numadd):
White = "" *numadd
return white + white.join (S.splitlines (True))
def numspaces (s):
return [Len (line)-len (Line.lstrip ()) To line in S.splitlines ()]
def delspaces (S, Numdel):
If Numdel > Min (numspaces (s)):
Raise ValueError, "removing more spaces than there"
Return ' \ n '. Join ([Line[numdel:] for line in S.splitlines ()])
def unindentblock (s):
Return delspaces (S, Min (numspaces (s))