-3

Assume that you have this class:

class ThisIsAClass

       pass

What´s the pass argument?, What does it do?. Im very confused about this..

  • It's not an argument. It's a NOP (no-operation) statement. It's there because Python's syntax requires *something* to be there even if you've got an empty class/function. (Did you not try googling at all??) – The Paramagnetic Croissant Jun 30 '14 at 23:38

2 Answers2

1

pass does nothing.

It's used in cases where syntax demands a statement, but you don't want to do anything else. In this case, you are creating a class (assuming you add the missing :) that has no attributes and no functionality. If you had omitted pass you would get a SyntaxError, because colons must be followed by a valid statement on the appropriate indentation level.

kindall
  • 178,883
  • 35
  • 278
  • 309
Andrew Gorcester
  • 19,595
  • 7
  • 57
  • 73
0

It's simply used when a statement is required, but you don't want any code actually executed. A common place in the Except portion of a try, except block.

blh83
  • 495
  • 5
  • 17