#!/usr/bin/python
#Filename:format.py
age = 25
name = 'saroop'
print('{0} is {1} years old'.format(name,age))
print('why is {0} playing with that python'.format(name))
结果:
[(3) root@Fedora~/Note/python]#./1format.py
saroop is 25 years old
why is saroop playing with that python
#首先定义了两个变量age 和name,pythonn变量自动匹配类型不需要自动定义类型
#这里说的是format函数的使用。
#format函数把变量格式化为字符串进行输出
#其中{0}对应的就是format的第一个参数name,{1}对应format的第二个参数age