理解%r
和%s
的区别
%r
会重现所表达的对象,%s
会将所有转成字符串
eg1:
print('i am %s years old' % 22) print('i am %r years old' % 22)
>>>>>>>>>>>>>>>>>>>>>>>>
i am 22 years old i am 22 years old
eg2:
t = 'i am %d years old' % 22 print('i said %s' % t) print('i said %r' % t)
>>>>>>>>>>>>>>>>>>>>>>>>
i said i am 22 years old i said 'i am 22 years old'
eg3:
import datetime d = datetime.date.today() print('%s' % d) print('%r' % d)
>>>>>>>>>>>>>>>>>>>>>>>>
2017-6-26 datetime.date(2017, 6, 26)