python书写的一些技巧

1,with可以在写入文件后自动将文件关闭`

with  open ('text.txt.', 'w')  as f:
           f.write('test')

f=open('text.txt','w')
   f.write('test')

要好
2,format 比 % 要好
3,from collections import Counter
Counter 在计数时特别好用

猜你喜欢

转载自blog.csdn.net/weixin_39995352/article/details/83791437