Python: String Operation
Revision as of 06:13, 30 January 2017 by Onnowpurbo (talk | contribs) (Created page with " ==Strip /n== line.strip() will remove all types of whitespaces from both ends of the line. You can use line.rstrip("\n") to remove only the trailing "\n". ==Join Line==...")
Strip /n
line.strip() will remove all types of whitespaces from both ends of the line. You can use line.rstrip("\n") to remove only the trailing "\n".
Join Line
Pakai str.join:
with open('file.txt') as f:
print " ".join(line.strip() for line in f)