【发布时间】:2014-10-18 22:35:36
【问题描述】:
In [4]: {'a': "hello"}['a']
Out[4]: 'hello'
我希望输出改为:
Out[4]: hello
实现这一目标最优雅的方法是什么?
我稍后也使用 repr().rjust() 将字典列表打印到格式整齐的表格中,我注意到 repr 函数还添加了令人讨厌的引号:
def print_dictionary(d): print repr(d['a']).rjust(10)
print_dictionary({'a':'hello'})
产量:
'hello'
当我想要时:
hello
【问题讨论】:
-
print({'a': "hello"}['a']),如果您不想要引号,为什么还要使用 repr?
标签: python dictionary