如何使用python打印用户输出的语句

2024-10-02 00:40:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一本python词典,如下所示:

dict1 = {'a':1, 'b':2, 'c':3}

到目前为止,我已经在Python 3中运行了以下代码:

for key, value in dict1.items() :   
    print (key* value,end='')

这给了我输出:cccbba

我的问题是如何打印-

Your answer : cccba.

Tags: key代码answerinforyourvalueitems
2条回答

像这样:

dict1 = {'a':1, 'b':2, 'c':3}

print ("Your answer : ",end='')

for key, value in dict1.items() :   
    print (key* value,end='')

你真的应该开始掌握^{}

>>> print("Your answer: {0}".format("".join([k * v for k, v 
                                             in dict1.items()])))
Your answer: acccbb

相关问题 更多 >

    热门问题