Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Coding Issue!
#1
Hello Everyone,

Why Is The “Pass” Keyword Used For In Python?

>>> if x==0:
pass
else:
print "x!=0"

Anyone tell me why it is used in python or Anyone tells me best wat to learn python. I want to explore more about python coding.
Reply
#2
the pass statement is a place holder statement that does nothing. it is useful if a statement requires a minimum of one line and you will add it it later. Or your a particular situation where you are executing code where a statement is required and you don't need to do anything in your code. It has been useful in a few situations.

You can buy books and study on websites. You can also download the Python Training Kit from Siraoops at www.siraoops.com. The training kit contains hundreds of programming exercises.

Hope this answers all of you questions,
John
Reply
#3
(Sep-13-2019, 08:33 AM)ankitdixit Wrote: Hello Everyone,

Why Is The “Pass” Keyword Used For In Python?

>>> if x==0:
pass
else:
print "x!=0"

Anyone tell me why it is used in python or Anyone tells me best wat to learn python. I want to explore more about python coding.

In spoken language it's: 'if x is equal zero do nothing, else print that x is not equal to zero.'. However, in spoken language and in Python it usually expressed:

# spoken language: "if x is not equal to zero notify the user about that"
if x != 0:
    print('x != 0')
EDIT:

Of course there is built-in help in Python (press 'q' key to exit help):

>>> help('pass')
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
(END)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
This Python example page explains the use of the pass statement to indicate empty functions, classes and loops.
Pass. Time passes. And often nothing happens. In Python we use the "pass" keyword (a statement) to indicate that nothing happens—the function, class or loop is empty.

With pass, we indicate a "null" block. Pass can be placed on the same line, or on a separate line. Pass can be used to quickly add things that are unimplemented.

Method example. Here we use the "pass" statement on two methods. These methods do nothing. But they can be called in Python code.

Result: Nothing happens when the pass methods are called. The pass can be used in other places in Python programs.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Very basic coding issue aary 4 2,413 Jun-03-2020, 11:59 AM
Last Post: buran
  Very basic coding issue mstichler 3 2,553 Jun-03-2020, 04:35 AM
Last Post: mstichler
  Coding issue 1557676 2 25,261 Aug-02-2019, 08:54 PM
Last Post: cvsae
  New member with simple coding issue shaikh 0 2,972 Apr-24-2017, 05:28 PM
Last Post: shaikh
  coding issue Lee 2 3,444 Feb-13-2017, 10:53 AM
Last Post: Lee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020