1. %
%是最常用的格式化输出形式,后面接类型,%s,%d,%c等等
name = input()print('I am %s' % name)
2.format
format也是常用格式化输出
print('i am {}, {}years old,{}kg'.format('pis',20,55)) print('i am {name}, {age}years old,{weight}kg'.format(name='pis',age=20,weight=55))
{xx}里面可以填key值,format中对应填写,如果不填就是按顺序一一配对。
3.dict
a = { 'd':123, 'c':456}print('i am %(d)s,%(c)syears old' % a)#i am 123,456years old
4.repr
name = 'pis'print('Item({})'.format(name))print('Item({!r})'.format(name))# Item(pis)# Item('pis')