473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

why pass statement?

Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None


Jul 18 '05 #1
11 2890
M-a-S wrote:
Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None

No. None is just a value (now variable), not a statment.

hth,
anton.
Jul 18 '05 #2
M-a-S wrote:

Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None


For readability. Pass makes more sense. You seem to think minimalism
is inherently good... (?)

-Peter
Jul 18 '05 #3

"M-a-S" <NO*****@hotmail.com> wrote in message
news:iR******************@twister.southeast.rr.com ...
Why is there the pass statement? I think, the expression statement would be enough:
class C:
None

while True:
None
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


Jul 18 '05 #4
A good idea! Thanks!

"John Roth" <ne********@jhrothjr.com> wrote in message news:vm************@news.supernews.com...

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

Jul 18 '05 #5
M-a-S wrote:
Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None


'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:
def f(): pass .... def g(): None .... import dis
dis.dis(f) 1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE dis.dis(g)

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,

--
Hans (ha**@zephyrfalcon.org)
http://zephyrfalcon.org/

Jul 18 '05 #6
M-a-S wrote:

"John Roth" <ne********@jhrothjr.com> wrote in message news:vm************@news.supernews.com...
You don't actally need Pass. A docstring is sufficient:

class C:
"this is a class"

while True:
"loop de loop de loop"

A good idea! Thanks!


Not a so good idea, since the pass statement is explicit (and explicit
is better than implicit).

My 2 explicit eurocents
Bruno

Jul 18 '05 #7

Originally posted by M-A-S
A good idea! Thanks! "John Roth" <ne********@jhrothjr.com> wrote in message news:vme-
q2*********@news.supernews.com"]news...s.supernews.co-
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


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.
--
Contact info (decode with rot13): ce******@bcrenznvy.pbz
Fcnzserr! Cyrnfr qb abg hfr va choyvp zrffntrf. V ernq gur yvfg, ab arrq gb PP.
Posted via http://dbforums.com
Jul 18 '05 #8

"Hans Nowak" <ha**@zephyrfalcon.org> wrote in message news:ma**********************************@python.o rg...
'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.
I know. I just state that there is NO need for it. Just define in __builtins__
pass = None and that's it.

BTW Algol-68 used 'skip' for both purposes (no action and no data).

Your code, using None, has the same effect. However, there's a slight
difference in the bytecode that is generated:
>>> def f(): pass ... >>> def g(): None ... >>> import dis
>>> dis.dis(f) 1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE >>> dis.dis(g)

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,

--
Hans (ha**@zephyrfalcon.org)
http://zephyrfalcon.org/

That's just a question of optimization.

And thank you for showing me how to dig to the code!

M-a-S
Jul 18 '05 #9

"Andrei" <se*@my.signature.com> wrote in message news:33****************@dbforums.com...
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.

I know, I do :-) It's too late to make a revolution.

--
Contact info (decode with rot13): ce******@bcrenznvy.pbz
Fcnzserr! Cyrnfr qb abg hfr va choyvp zrffntrf. V ernq gur yvfg, ab arrq gb PP.
Posted via http://dbforums.com

Jul 18 '05 #10
JCM
M-a-S <NO*****@hotmail.com> wrote:
Why is there the pass statement? I think, the expression statement would be enough: class C:
None while True:
None


Because emacs python-mode knows to dedent the next line after a pass :)
Jul 18 '05 #11

"JCM" <jo******************@myway.mathworks.com> wrote in message
news:bk**********@ginger.mathworks.com...
M-a-S <NO*****@hotmail.com> wrote:
Why is there the pass statement? I think, the expression statement
would be enough:
class C:
None

while True:
None


Because emacs python-mode knows to dedent the next line after a pass

:)

Nice.

pass is the guaranteed-to-do-nothing identity statement (function
operating on the interpreter state). def f(): pass generates a
*miminal* function object with a *minimal* code object. This is at
least potentially useful for testing or investigating the
implementation. The alternative of an expression statement adds code
to the code body. The alternative of a doc string generates a string
object attached somewhere to the no-longer-minimal function or code
object. Indeed, the way to test the effect of either alternative is
to start with the minimum and then define f2 and look for the
difference -- as one of the earlier posters in this thread did do
(using dis module to 'look') for the None expression.

Terry J. Reedy

Jul 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
41
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
4
by: Robert | last post by:
What is the syntax to use in a VBA script to execute a pass-through? Thanx
2
by: Robert | last post by:
when using the following function to create a pass through query is there a way to set the query property, "Returns Rows" to no. The default is yes. Since we are planning to create the pass...
3
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around...
2
by: Bob Alston | last post by:
If you have an access form with record source being a straightforward query and where clause in the form definition, will the query be sent to the back end jet/Access database and executed there,...
6
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.