Python学习笔记

来源:互联网 发布:php微社区源码 编辑:程序博客网 时间:2024/06/06 10:37

Python学习中ing…
《A byte of Python 3》学习摘要
Chapter 5
format 方法
有时我们并不想用其他信息来构造字符串。这儿format() 方法就很有用。

1 #!/usr/bin/python2 # Filename: str_format.py3 age = 254 name = 'Swaroop'5 print('{0} is {1} years old'.format(name, age))6 print('Why is {0} playing with that python?'.format(name))

输出:

1 $ python str_format.py2 Swaroop is 25 years old3 Why is Swaroop playing with that python?
0 0
原创粉丝点击