Python学习中ing…
《A byte of Python 3》学习摘要
Chapter 5
format 方法
有时我们并不想用其他信息来构造字符串。这儿format() 方法就很有用。
1 #!/usr/bin/python
2 # Filename: str_format.py
3 age = 25
4 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.py
2 Swaroop is 25 years old
3 Why is Swaroop playing with that python?