1 #不推荐这种方式,因为每个要拼接的字符串都在不同内存位置
2 a =
'Computer'
3 b = 11
4 c = 16.5
5 print(
'name:' + a +
'age:' + str(b) +
'job:' + str(c),
'方式一')
6
7 # 字符拼接(%s字符串变变量,%d=整数变量,%f=浮点数变量)
8 print(
'''
9 name:%s
10 age:%d
11 job:%f
12 ''' % (a, b, c),
'方式二')
13
14 str1 =
'''
15 name:{0}
16 age:{1}
17 job:{2}'''
18 print(str1.format(a, b, c),
'方式三')
转载于:https://www.cnblogs.com/xh4528/p/6497666.html
转载请注明原文地址: https://win8.8miu.com/read-1547702.html