[英]Printing multiple dictionary keys on one line
I have this code:我有这个代码:
my_dict = {'key1':'roger','key2':'bootsma'}
print (my_dict['key1']), (my_dict['key2'])
But i does not seem to be able to print on one line as one would suspect.但我似乎无法像人们怀疑的那样在一行上打印。 It does print one key but cannot print a key after that on same line.它确实打印了一个键,但不能在同一行上打印一个键。
The generally acceptable answer to your question is this:您的问题的普遍可接受的答案是:
print('{} {}'.format(my_dict['key1'], my_dict['key2']))
Some other possibilities:其他一些可能性:
print('%s %s' % (my_dict['key1'], my_dict['key2']))
# or
print(' '.join(my_dict.values()))
# or
print(my_dict['key1'], end='')
print(my_dict['key2'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.