笨办法06字符串(string)和文本

来源:互联网 发布:网侠安卓电视直播软件 编辑:程序博客网 时间:2024/06/06 00:57

代码如下:

# coding : utf-8x = "There are %d types of people." % 10binary = "binary"do_not = "don't"y = "Those who know %s and those who %s." % (binary, do_not)print xprint y print "I said: %r." % xprint "I also said: %s." % y #将原代码中的‘’单引号删去了,与%r的打印结果做对比hilarious = Falsejoke_evaluation = "Isn't that joke so funny?! %r"print ( joke_evaluation % hilarious )w = "This is the left side of..."e = "a string with a right side."print w + e 

运行结果:
这里写图片描述

%r是repr搜索;%s是str;前者是被repr处理后的string对象,后者直接是string对象。
使用%r打印出的是字符串会带上引号‘’,使用%s则不会

原创粉丝点击