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