为什么函数有字典 [英] why function got dictionary

查看:49
本文介绍了为什么函数有字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在寻求以下解释:


Python 2.5.2(r252:60911,2008年4月8日, 21:49:41)

[gCC 4.2.3(Ubuntu 4.2.3-2ubuntu7)] on linux2

输入help,copyright, ;学分"或许可证或欲获得更多信息。


>> def g():return



....


>> g .__ dict__



{}


问:为什么功能得到字典?它的用途是什么?

Thx,Andy

解决方案

AlFire写道:





我正在寻求以下解释:


Python 2.5.2(r252:60911, 2008年4月8日,21:49:41)

[gCC 4.2.3(Ubuntu 4.2.3-2ubuntu7)] on linux2

输入help,版权所有,信用或许可证或欲获得更多信息。


>> def g():return



...


>> g .__ dict__



{}


问:为什么函数有字典?它用于什么?



因为它是一个对象,你可以做到例如


g.exposed = True


或类似的东西。


Diez


On 17 avr,16:06,AlFire< spamgrinder .tryla ... @ gmail.comwrote:





我正在寻求以下解释:


Python 2.5.2(r252:60911,2008年4月8日,21:49:41)

[GCC 4.2.3(Ubuntu 4.2.3-2ubuntu7) ] on linux2

输入help,copyright,credit等等。或许可证或欲获得更多信息。


>> def g():return



...


>> g .__ dict__



{}


问:为什么函数有字典?它用于什么?



答:Python中的所有(或几乎)都是一个对象。包括函数,

类,模块等。


Diez B. Roggisch写道:

< blockquote class =post_quotes>
>>
问:为什么函数有字典?它用于什么?



,因为它是一个对象,你可以做,例如



你的意思是下面的一个对象感觉?


>> isinstance(g,object)



True

我在哪里可以阅读更多相关内容?


Andy


Hi,

I am seeking an explanation for following:

Python 2.5.2 (r252:60911, Apr 8 2008, 21:49:41)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>def g(): return

....

>>g.__dict__

{}

Q: why function got dictionary? What it is used for?
Thx, Andy

解决方案

AlFire wrote:

Hi,

I am seeking an explanation for following:

Python 2.5.2 (r252:60911, Apr 8 2008, 21:49:41)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>def g(): return

...

>>g.__dict__

{}

Q: why function got dictionary? What it is used for?

because it is an object, and you can do e.g.

g.exposed = True

or similar stuff.

Diez


On 17 avr, 16:06, AlFire <spamgrinder.tryla...@gmail.comwrote:

Hi,

I am seeking an explanation for following:

Python 2.5.2 (r252:60911, Apr 8 2008, 21:49:41)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>def g(): return

...

>>g.__dict__

{}

Q: why function got dictionary? What it is used for?

A: everything (or almost) in Python is an object. Including functions,
classes, modules etc.


Diez B. Roggisch wrote:

>>
Q: why function got dictionary? What it is used for?


because it is an object, and you can do e.g.

you mean an object in the following sense?

>> isinstance(g,object)

True
where could I read more about that?

Andy


这篇关于为什么函数有字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆