学习网站一:
http://c.biancheng.net/view/2187.html
Python中Print()函数的用法___实例详解(全,例多)
https://blog.csdn.net/weixin_69553582/article/details/125403845
Python 文档目录
https://docs.python.org/zh-cn/3/contents.html
python Format()函数的用法
https://blog.csdn.net/weixin_69553582/article/details/129830874
内置函数:
内置函数的具体功能和用法,可通过访问 https://docs.python.org/zh-cn/3/library/functions.html 进行查看
=============================================================================
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe8 in position 39: ordinal not in range(128)
解决方法:
在Python程序最前面加上以下语句:
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8’)
将默认编码设置为utf-8
python处理列表或字典包含中文乱码问题
解码之前
dict = {‘name’: ‘张三’}
print dict
{‘name’: ‘xe5xbcxa0xe4xb8x89’}
使用json解码后
import json
dict = {‘name’: ‘张三’}
print json.dumps(dict, encoding=“UTF-8”, ensure_ascii=False)
{‘name’: ‘张三’}
例子2:
===============================================================================
Python2 与 Python3 print 不换行
Python 3.x
在 Python 3.x 中,我们可以在 print() 函数中添加 end=“” 参数,这样就可以实现不换行效果。
在 Python3 中, print 函数的参数 end 默认值为 “\n”,即end=“\n”,表示换行,给 end 赋值为空, 即end=“”,就不会换行了,例如:
end=“” 可以设置一些特色符号或字符串:
Python2.x 实例
如果有变量,我们可以在逗号 , 后面直接添加变量:
注意:这种输出方法,在 , 末尾会有一个空格输出,类似于使用了 Python 3 的 end=" "。
Python2.x 与 Python3.x 兼容模式
如果 Python2.x 版本想使用 Python3.x 的 print 函数,可以导入 future 包,该包禁用 Python2.x 的 print 语句,采用 Python3.x 的 print 函数。
以下代码在 Python2.x 与 Python3.x 都能正确执行:
注:Python3.x 与 Python2.x 的许多兼容性设计的功能可以通过 future 这个包来导入。