python的两种不同print print , 加逗号和print "%s %s" 不一样
来源:互联网 发布:管家婆远程桌面该软件 编辑:程序博客网 时间:2024/05/22 03:06
对于两种实际结果显示一样的写法
print a,b 和 print "%s %s"
他们两个内部其实是不一样的。。。
print a,b 我认为相当于调用 print a 然后print b 然后 print c,每次都单独执行了一个print
而print "%s %s" % (a,b) 就是一次执行完,只执行了一次print
为什么这样说 ??在windows环境下,py2.7,来看这样一个例子
代码如下
>>> a , b = "中", u"文">>> print a,b中 文>>>>>> print "%s %s" % (a, b)
看看出错的效果吧~~
下面那个print的效果,应该是相当于 a+b ,试试看a+b也会出现相同的错
因为
>>> a'\xe4\xb8\xad'>>> >>> bu'\u6587'>>>
a,b 不一样,没办法相加
要相加,要同时能被打印,要根据平台解码或者编码成一样的才行,比如说
>>> print "%s %s" % (a.decode("gbk"), b)中 文>>>>>>>>> print "%s %s" % (a, b.encode("gbk"))中 文>>>>>>
很神奇吧。
这里的decode 和 encode 的主语是,【二进制】
【二进制】解码
【二进制】编码
\x 就是16进制
(mac和linux小伙伴,把对应的gbk改成utf-8就好了)
阅读全文
0 0
- python的两种不同print print , 加逗号和print "%s %s" 不一样
- print %.*s
- python学习笔记之 print加逗号
- zoj3762Alice's Print Service
- print函数中%r和%s
- 《python print -> print() 》
- print >>
- python 不同版本之间的print
- ZOJ Alice's Print Service
- hdu4791 Alice's Print Service
- HDU4791 Alice's Print Service
- python的输出 print print, write
- python2的print和python3的print()
- python 的print输出
- 关于已知两点经纬度求球面最短距离的公式推导
- Egret 之 消除游戏 开发 PART 6 Egret elimination game development PART 6
- [UVa 11093] 环形跑道(Just Finish it up)
- 天易48----Springmvc结合rabbitmq简单示例
- 第5章 继承
- python的两种不同print print , 加逗号和print "%s %s" 不一样
- SPOJ
- JavaWeb学习总结(一)——JavaWeb开发入门
- 我的博客
- Unity3D 入门 游戏开发 Unity3D portal game development
- Android 2017你该用到的开源框架
- Python简单爬虫
- 解题报告:HDU_4947:GCD Array 莫比乌斯反演+树状数组
- Python 函数参数