split and join : String join « String « Python






split and join

split and join


s = "this   is\na\ttest"                          
print s 

print s.split()                                    

print " ".join(s.split())                          

# split without any arguments splits on whitespace. 

# You can normalize whitespace by splitting a string with split and then 
# rejoining it with join, using a single space as a delimiter. 
# This is what the info function does to collapse multiline doc 
# strings into a single line.
           
       








Related examples in the same category

1.Joining stringsJoining strings
2.Join a listJoin a list
3.String JOINString JOIN
4.Printing a ListPrinting a List
5.Splitting a StringSplitting a String