name='liming'
age = 20
#1 字符串拼接,变量age必须是str类型
print('he is '+str(age)+' years old')
执行结果
he is 20 years old
#2 %s代表变量,
print('he is %s years old' % age)
执行结果
he is 20 years old
#3 format
print('{} is {} years old'.format(name,age))
print('{0} is {1} years old'.format(name,age))
print('{name_} is {age_} years old'.format(name_=name,age_=age))
执行结果
liming is 20 years old
liming is 20 years old
liming is 20 years old