本文介绍了打印字典名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还是新的。学习属性和功能等等。


对不起,如果这是显而易见的,但是如果我为某些

词典定义一个函数,我怎么能只打印字典的名称?


例如假设应用程序,目录,网站是模块中定义的词典,

如何在与其他人做其他事情之前打印他们的名字。


def printdict( dicts = [app,dirs,sites]):

dict in dicts:

打印???


谢谢


rpd

Still new. Learning attributes and functions and so on.

Sorry if this is obvious, but if I''m defining a function for some
dictionaries, how can I print just the names of the dictionaries?

E.g. assuming apps, dirs, sites are dictionaries defined in the module,
how can I print just their names before doing other things with them.

def printdict(dicts=[apps, dirs, sites]):
for dict in dicts:
print ???

Thank you

rpd

推荐答案




简答:你不能。




....

Jay Graves



Short answer: You can''t.

http://pyfaq.infogami.com/how-can-my...e-of-an-object

....
Jay Graves




[''alpha'',''beta'']


当然,最简单的方法就是使用元组(字典,字符串)。


作为旁注,因为dict是内置类型,功能,它可能不是

将它用作循环变量的好方式。


THN


[''alpha'', ''beta'']

Of course, the easiest way is just to use a tuple (dict,string).

As a side note, since dict is a builtin type and function, it might not
be good style to use it as a loop variable.

THN



这篇关于打印字典名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:24