M
M-a-S
Why is there the pass statement? I think, the expression statement would be enough:
class C:
None
while True:
None
class C:
None
while True:
None
No. None is just a value (now variable), not a statment.M-a-S said:Why is there the pass statement? I think, the expression statement would be enough:
class C:
None
while True:
None
M-a-S said:Why is there the pass statement? I think, the expression statement would be enough:
class C:
None
while True:
None
M-a-S said:Why is there the pass statement? I think, the expression statement would be enough:
class C:
None
while True:
None
M-a-S said:Why is there the pass statement? I think, the expression statement would be enough:
class C:
None
while True:
None
A good idea! Thanks!
(e-mail address removed)"]news:[email protected]
m[/url]...You don't actally need Pass. A docstring is sufficient:
class C:
"this is a class"
while True:
"loop de loop de loop"
John Roth
M-a-S said:> A good idea! Thanks!
Hans Nowak said:'pass' is a no-op statement that, according to the tutorial, is used when a
statement is required syntactically but the program requires no action.
Your code, using None, has the same effect. However, there's a slight
difference in the bytecode that is generated:
1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
1 0 LOAD_GLOBAL 0 (None)
3 POP_TOP
4 LOAD_CONST 0 (None)
7 RETURN_VALUE
This is probably irrelevant, but it wouldn't be correct to say that using pass
is exactly the same as using None.
HTH,
Andrei said:I find "pass" shows that something could be there, sort of "insert stuff
here if you like/need to". A string as such doesn't have that effect.
Obviously you could always make up some useless statement instead of
pass, but pass just looks more elegant IMO. You probably should use it
if you plan on showing your code to others.
M-a-S said:Why is there the pass statement? I think, the expression statement would be enough:
class C:
None
while True:
None
JCM said:would be enough:
Because emacs python-mode knows to dedent the next line after a pass
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.