python中的字符串格式函数str.format()
来源:互联网 发布:mac 能装破解版软件么 编辑:程序博客网 时间:2024/05/27 12:22
1 #使用str.format()函数
2
3 #使用'{}'占位符
4 print('I\'m {},{}'.format('Hongten','Welcome to my space!'))
5 >>> I'm Hongten,Welcome to my space!
6 print('#' * 40)
7
8 #也可以使用'{0}','{1}'形式的占位符
9 print('{0},I\'m {1},my E-mail is {2}'.format('Hello','Hongten','hongtenzone@foxmail.com'))
>>> Hello,I'm Hongten,my E-mail is hongtenzone@foxmail.com
10 #可以改变占位符的位置
11 print('{1},I\'m {0},my E-mail is {2}'.format('Hongten','Hello','hongtenzone@foxmail.com'))
12 >>> Hello,I'm Hongten,my E-mail is hongtenzone@foxmail.com
13 print('#' * 40)
14 ########################################
15 #使用'{name}'形式的占位符
16 print('Hi,{name},{message}'.format(name = 'Tom',message = 'How old are you?'))
17 >>> Hi,Tom,How old are you?
18 print('#' * 40)
19 ########################################
20 #混合使用'{0}','{name}'形式
21 print('{0},I\'m {1},{message}'.format('Hello','Hongten',message = 'This is a test message!'))
22 >>> Hello,I'm Hongten,This is a test message!
23 print('#' * 40)
0 0
- python中的字符串格式函数str.format()
- python中的字符串格式函数str.format()
- Python str.format()函数
- python: str.format (字符串 格式化)
- python 中的%s和%r、str.format()函数
- Python字符串format函数
- php中的sprintf()函数的format格式字符串
- C#中的 Format格式字符串
- python中的format函数
- Python 之 str.format()
- python-str-format
- python,str,format
- Python str.format
- python字符串format函数学习
- python-format函数格式化字符串
- python格式化字符串format函数
- python 格式化字符串 format() 函数
- python字符串内建函数str.index()和str.rindex()
- 机器学习笔记2——分类
- 百度登录加密协议分析(下)
- rails 练习6 --让使用者可以投票
- 数据结构练习题及答案
- ListView异步加载图片方法和滚动优化
- python中的字符串格式函数str.format()
- 如何提高浮点数变整数的精度
- ecshop二次开发--前台秒杀
- HTM层级实时记忆开发平台Nupic安装方法(pYTHON VERSION)
- 第3节--PyDev配置
- eclipse如何使用git从远程仓库clone项目?
- IE FF 兼容问题(1)
- CNN处理图像的一点总结
- Oracle 11g安装GI后,运行roothas.pl脚本报错libcap.so.1找不到