filename='alice.txt'
with open(filename,encoding='utf-8') as f:
contents=f.read()#得到一个字符串
print(type(contents))
words=contents.split()#得到一个列表
print(type(words))
print(len(words))
try:
fname='alice.txt'
with open(fname,encoding='utf-8') as f:
c=f.read()
d=c.split()
except FileNotFoundError:
print(f"sorry, the {fname} didn't exist.")
else:
print(len(d))
python10.3.6
最新推荐文章于 2024-07-18 19:54:29 发布