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