VAR和_VAR_有什么区别? [英] What's the difference between VAR and _VAR_?
问题描述
我是python中的新手,我想知道
下面两个代码部分的区别是什么:
< br $>
(I)
class TestResult:
_pass_ =" pass"
_fail_ =" fail"
_exception_ =" exception"
(II)
class TestResult:
pass =" ;传递'
失败="失败>
例外="例外"
感谢您的帮助。
Hi,
I''m new in python and I was wondering what''s the difference between
the two code section below:
(I)
class TestResult:
_pass_ = "pass"
_fail_ = "fail"
_exception_ = "exception"
(II)
class TestResult:
pass = "pass"
fail = "fail"
exception = "exception"
Thanks for your help.
推荐答案
Johnny Lee写道:
Johnny Lee wrote:
我是蟒蛇新手,我想知道
下面的两个代码部分有什么区别:
(I)
类TestResult:
_pass_ =" pass"
_fail_ =失败
_exception_ =" exception"
(II)
class TestResult:
pass =" pass"
fail =" ;失败" ;
exception =" exception"
感谢您的帮助。
I''m new in python and I was wondering what''s the difference between
the two code section below:
(I)
class TestResult:
_pass_ = "pass"
_fail_ = "fail"
_exception_ = "exception"
(II)
class TestResult:
pass = "pass"
fail = "fail"
exception = "exception"
Thanks for your help.
每个人之间没有什么不同变量名为''x''和一个
命名为''_x_''。这里的区别在于pass是一个关键字,所以
pass =''pass''
是非法的。
-
Erik Max Francis&& ma*@alcyone.com && http://www.alcyone.com/max/
美国加利福尼亚州圣何塞市&& 37 20 N 121 53 W&& AIM erikmaxfrancis
经验是每个人都给出错误的名字。
- 奥斯卡王尔德
There''s nothing per se different between a variable named ''x'' and one
named ''_x_''. The difference here is that pass is a keyword, so
pass = ''pass''
is illegal.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Experience is the name everyone gives to their mistakes.
-- Oscar Wilde
就像你一样说,以下两个代码部分完全相同?
(I)
class TestResult:
_passxxx_ ="通过
(II)
class TestResult:
passxxx =" pass"
As what you said, the following two code section is totally the same?
(I)
class TestResult:
_passxxx_ = "pass"
(II)
class TestResult:
passxxx = "pass"
Johnny Lee写道:
Johnny Lee wrote:
正如你所说,以下两个代码部分完全相同?
(I)
类TestResult:
_passxxx_ =" pass"
(II)
class TestResult:
passxxx =" pass"
As what you said, the following two code section is totally the same?
(I)
class TestResult:
_passxxx_ = "pass"
(II)
class TestResult:
passxxx = "pass"
不,当然不是。一个定义了一个名为`_passxxx_'的类变量,
其他定义一个名为`passsxxx''。
-
Erik Max Francis&& ma*@alcyone.com && http://www.alcyone.com/max/
美国加利福尼亚州圣何塞市&& 37 20 N 121 53 W&& AIM erikmaxfrancis
经验是每个人都犯错的名字。
- 奥斯卡王尔德
No, of course not. One defines a class varaible named `_passxxx_'', the
other defines one named `passsxxx''.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Experience is the name everyone gives to their mistakes.
-- Oscar Wilde
这篇关于VAR和_VAR_有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!