需要放“自我”在每种方法中 [英] The need to put "self" in every method

查看:58
本文介绍了需要放“自我”在每种方法中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我只是想知道是否需要放自我作为一个类中每个方法的第一个

参数因为,如果它总是需要的话,

为什么有义务写它?难道不是隐含的吗?


或者这是这种方式的特殊原因吗?


谢谢。

Hi,

i was just wondering about the need to put "self" as the first
parameter in every method a class has because, if it''s always needed,
why the obligation to write it? couldn''t it be implicit?

Or is it a special reason for this being this way?

Thanks.

推荐答案

Fernando M.写道:
Fernando M. wrote:


我只是想知道需要把自我作为一个类中每个方法的第一个参数因为,如果它总是需要的话,为什么有义务写呢?难道不是隐含的吗?

或者这是一个特殊的原因吗?

谢谢。
Hi,

i was just wondering about the need to put "self" as the first
parameter in every method a class has because, if it''s always needed,
why the obligation to write it? couldn''t it be implicit?

Or is it a special reason for this being this way?

Thanks.



原因可以在python语句的输出中找到import

this。明确比隐含更好。


问候

史蒂夫

-

Steve Holden +1 703 861 4237 +1 800 494 3119

Holden Web LLC http:// www.holdenweb.com/

Python网页编程 http: //pydish.holdenweb.com/


The reason can be found in the output from the python statement "import
this". Explicit is better than implicit.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/


" Fernando M." < FE ***************** @ gmail.com>在消息中写道

news:11 ********************* @ g14g2000cwa.googlegro ups.com ...
"Fernando M." <fe*****************@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...


我只是想知道需要放自我。作为一个类中每个方法的第一个参数因为,如果它总是需要的话,为什么有义务写呢?难道不是隐含的吗?

或者这是这种方式的特殊原因吗?


有两个不同的问题。


1.如果将自己设为关键字,则不需要

在方法标题中。然而,这将是一个影响几乎每个存在的脚本的主要的不可比拟的变化。

也有些人使用其他词而不是自己。 (顺便说一下,这将导致性能提升。)


2.有一些关于制作''的话题。 ''运营商允许一个

隐含的实例。我不确定这是什么状态。


这两个实际上是分开的问题;要么可以在没有其他人的情况下完成



John Roth

谢谢。
Hi,

i was just wondering about the need to put "self" as the first
parameter in every method a class has because, if it''s always needed,
why the obligation to write it? couldn''t it be implicit?

Or is it a special reason for this being this way?
There are two different issues.

1. If self was made a keyword, there would be no need for
it in the method header. However, that would be a major
incompabible change affecting almost every script in existance.
Also some people use other words than self. (It would,
by the way, result in a performance improvement.)

2. There''s been some talk of making the ''.'' operator allow an
implied instance. I''m not sure what the status of this is.

These two are actually separate issues; either could be
done without the other.

John Roth
Thanks.






Fernando M.写道:
Fernando M. wrote:
我只是想知道是否需要放置自我。作为一个类中每个方法的第一个参数因为,如果它总是需要的话,为什么有义务写呢?难道不是隐含的吗?
i was just wondering about the need to put "self" as the first
parameter in every method a class has because, if it''s always needed,
why the obligation to write it? couldn''t it be implicit?




py>导入这个

蒂姆·彼得斯的Python之禅


美丽胜过丑陋。

显式优于隐式。

....

STeVe



py> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
....
STeVe


这篇关于需要放“自我”在每种方法中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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