-2
In [4]: {'a': "hello"}['a']
Out[4]: 'hello'
我所要的輸出改爲:如何在沒有引號的情況下打印一個dicionary的字符串值?
Out[4]: hello
什麼是最優雅的方式來實現這一目標? 。
我也使用再版()rjust()稍後打印的詞典列表成整齊的格式化的表格,我注意到再版功能還增加了引號是煩人:
def print_dictionary(d): print repr(d['a']).rjust(10)
print_dictionary({'a':'hello'})
產量:
'hello'
時,我想:
hello
'repr'打印值的表示形式,而不是值本身,在字符串的情況下包含引號。 – davidism 2014-10-18 22:37:59
'print({'a':「hello」} ['a'])',如果你不想引號,爲什麼要使用repr? – 2014-10-18 22:38:25
http://stackoverflow.com/questions/7784148/understanding-repr-function-in-python – 2014-10-18 22:51:51