How do I write a list to a file?

How do I write a list to a file?
Answer
Python – How to write a list to a file?
  1. Using write method: #!/usr/bin/python l1=[‘hi’,’hello’,’welcome’] f=open(‘f1.txt’,’w’) for ele in l1: f.write(ele+’n’) f.close() …
  2. Using string join method: …
  3. Using string join along with with open syntax: …
  4. Using the writelines method:
 

Tìm kiếm

Back
Top