# string format
template ='{0:.2f} {1:s} worths {2:d} USD'print(template.format(68,"RMB",10))print(template.format(112,"JPY",1))
68.00 RMB worths 10 USD
112.00 JPY worths 1 USD
# dynamic reference# python中变量的类型由数决定,变量无需声明即可赋值,变量的数据类型可动态改变
a =1.4
a ="abc"
# strong type
a =1.4
b =5
c ="abc"# type查看变量类型print(type(a))print(type(b))print(type(c))print(a + b)try:print(a + c)except TypeError as e:print(e)print(str(a)+ c)
<class 'float'>
<class 'int'>
<class 'str'>
6.4
unsupported operand type(s) for +: 'float' and 'str'
1.4abc