笨办法学python习题6 字符串和文本
来源:互联网 发布:淘宝网男花保 套装 编辑:程序博客网 时间:2024/05/18 16:57
这次的习题学习格式化控制符,在下面的代码中。
字符串中的格式化字符串类似规一个规定好只能盛放特定液体的罐子。牛奶瓶子装牛奶、茶杯装茶
%d:装10进制的整形数据
%s:装字符串类型的数据
%r : 装任何类型的数据
x = "There are %d types of people." %10 binary = "binary"do_not = "don't"y = "Those who know %s and those who %s." %(binary , do_not) print xprint yprint "I said : %r." %x print "I also said '%s' " %y hilarious = True joke_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输出结果为:
mystuff simengred$ python ex6.pyThere are 10 types of people.Those who know binary and those who don't.I said : 'There are 10 types of people.'.I also said 'Those who know binary and those who don't.' Isn't that joke so funny?! TrueThis is the left side of ...a string with a right side.
特别注意的2点:
1,%s打印的数据是“ ”(引号)内部的内容,要想打印出引号,需要在%s两侧加上引号:
print "I also said '%s' " %y而%r 则是无论什么都打印,不过双引号会编程单引号。
不过%r 用来做调试的使用
2,格式化控制符的个数应该与参数保持一致,不然运行程序的时候会报错。
阅读全文
0 0
- 笨办法学python习题6 字符串和文本
- 笨方法学Python 习题 6: 字符串(string)和文本
- 笨方法学习Python-习题6:字符串(string)和文本
- 笨办法学python习题20 函数和文件
- 习题6 字符串和文本
- 习题6--字符串和文本
- 笨办法06字符串(string)和文本
- 本办法学python习题25 更多更多的实践
- sudsn 笨办法学Python 习题13
- 《笨办法学python》习题38 40
- 笨办法学python之习题26
- 笨办法学python 习题46
- 笨办法学python 习题46-windows
- 笨办法学Python-习题0 准备工作
- 笨办法学Python习题11 提问
- 笨办法学python 习题24
- 笨办法学python习题3 数字和数学计算
- 笨方法学Python 习题 20: 函数和文件
- Linux系统编程(1)——文件与I/O之C标准I/O函数与系统调用I/O(尹成清华毕业生)
- Lua 元表简介
- Golang中位运算的详细理解
- 大数据正式4
- 省市二级联动
- 笨办法学python习题6 字符串和文本
- 4.设置bootargs启动时挂载
- springmvc+tomcat图片上传后如何立即刷新出来
- Unity Shader入门精要 阅读笔记 前言
- 【分治法】快速排序及C++代码
- Unity Shader入门精要 阅读笔记一
- TCP三次握手四次挥手抓包解析
- 心得体会
- MVP请求