How to use the pass statement?

前端 未结 15 2395
旧时难觅i
旧时难觅i 2020-11-22 15:03

I am in the process of learning Python and I have reached the section about the pass statement. The guide I\'m using defines it as being a Null sta

15条回答
  •  醉酒成梦
    2020-11-22 15:29

    Suppose you are designing a new class with some methods that you don't want to implement, yet.

    class MyClass(object):
        def meth_a(self):
            pass
    
        def meth_b(self):
            print "I'm meth_b"
    

    If you were to leave out the pass, the code wouldn't run.

    You would then get an:

    IndentationError: expected an indented block
    

    To summarize, the pass statement does nothing particular, but it can act as a placeholder, as demonstrated here.

提交回复
热议问题