%r与%s区别

%s与%r的区别:

%r对应的是python的repr函数
print "%r" % s 等于 print repr(s)

  1. print "%s" % s 等于 print str(s)%

# %s ⇒ str(),比较智能;

# %r ⇒ repr(),处理较为简单和直接;

>> s = 'world'

>> print('hello %s'%s) 

hello world 

>> print('hello %r'%s) 

hello 'world' 

>> str(s) 

'world' 

>> repr(s)

"'world'"

猜你喜欢

转载自blog.csdn.net/zjc910997316/article/details/82931276