博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
笨办法06字符串(string)和文本
阅读量:7006 次
发布时间:2019-06-27

本文共 628 字,大约阅读时间需要 2 分钟。

代码如下:

1 # coding : utf-8 2 x = "There are %d types of people." % 10 3 binary = "binary" 4 do_not = "don't" 5 y = "Those who know %s and those who %s." % (binary, do_not) 6  7 print x 8 print y  9 10 print "I said: %r." % x11 print "I also said: %s." % y #将原代码中的‘’单引号删去了,与%r的打印结果做对比12 13 hilarious = False14 joke_evaluation = "Isn't that joke so funny?! %r"15 16 print ( joke_evaluation % hilarious )17 18 w = "This is the left side of..."19 e = "a string with a right side."20 21 print w + e

运行结果:


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

转载于:https://www.cnblogs.com/p36606jp/p/7544175.html

你可能感兴趣的文章
auto_increment 自增键的一些说明
查看>>
从Exchange 通往Office 365系列(十一)发布OWA及Exchange ActiveSync
查看>>
培训用linux基础命令
查看>>
linux shell 编程13 获取时间
查看>>
webservice的两个解决方案
查看>>
TCP/IP三次握手和HTTP过程
查看>>
中国制造走出国门:谁说了算?
查看>>
我的友情链接
查看>>
Linux简单安装Node.js
查看>>
工业以太网怎么理解
查看>>
海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践...
查看>>
探秘 Dubbo 的度量统计基础设施 - Dubbo Metrics
查看>>
云原生的新思考,为什么容器已经无处不在了
查看>>
阿里云CDN技术掌舵人文景:相爱相杀一路狂奔的这十年
查看>>
impdp导入输出
查看>>
我的友情链接
查看>>
Hadoop 2.7.5 集群搭建基于CentOS7u3
查看>>
python pandas.DataFrame选取、修改数据最好用.loc,.iloc,.ix
查看>>
JAVA获取DLL文件版本
查看>>
mac下sphinx写rst文档
查看>>