编写一个程序生成列表[11,22,33,44,55,66,77,88,99],将其写入文件python1.txt中,然后从文件中读出该列表,用print()函数输出
时间: 2023-05-21 21:03:49 浏览: 438
py代码-列表ls=[1,2,3,4,5,6,7,8,9],编程去除ls中的素数,并输出结果列表
以下是生成列表、写入文件和读取文件的代码:
```python
# 生成列表
my_list = [11, 22, 33, 44, 55, 66, 77, 88, 99]
# 写入文件
with open("python1.txt", "w") as f:
for item in my_list:
f.write(str(item) + "\n")
# 读取文件并输出
with open("python1.txt", "r") as f:
lines = f.readlines()
my_list = [int(line.strip()) for line in lines]
print(my_list)
```
输出结果为:
```
[11, 22, 33, 44, 55, 66, 77, 88, 99]
```
阅读全文