参考:
https://blog.youkuaiyun.com/weixin_33594195/article/details/116173282
https://blog.youkuaiyun.com/weixin_39914752/article/details/111435978
- 中文的支持 程度:python3默认支持 中文 默认用utf-8编码,python2默认用ascall编码,需要指定,通过:
#encoding: utf-8
- import 文件时,对于python2,需要把文件夹变为模块(加入__init__.py)才能进行import,否则报错
- with open的方式
python3:
with open(r'd:\ssss.txt','w',encoding='utf-8') as f:
f.write(u'中文')
python2中需要加上:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
with open(r'd:\sss.txt','w') as f:
f.write(unicode("\xEF\xBB\xBF", "utf-8"))#函数将\xEF\xBB\xBF写到文件开头,指示文件为UTF-8编码。
f.write(u'中文')
- 整除
- 数据类型