How to write a list to a text file in Python

1 Answer

0 votes
a_list = ["python", "java", "c#", "c", "c++"]

file = open('d:\\data.txt', 'w')

for item in a_list:
    file.write("%s\n" % item)

'''
run:

python
java
c#
c
c++

'''

 



answered Oct 21, 2017 by avibootz

Related questions

2 answers 259 views
259 views asked Jun 22, 2020 by avibootz
1 answer 195 views
2 answers 286 views
2 answers 362 views
2 answers 209 views
...