+ 1
What is pass in python
2 Respuestas
+ 5
one of the first terms i heard about in python was pass (this is what i can remember, so anyone can correct me if i'm wrong). pass in my opinion is like a comment but unignored by the system, though using it will have no real effect on your output. in short terms it is read, but has no real effect (and is a placeholder if a code is needed)
+ 4
You use pass within a function to 'exit' the function code block.
It is useful when you are making say a template where you can outline a bunch of function names without actually giving them any further code. eg:
def test():
pass
def test2():
pass
then later on you can come back and fill in the code while developing.
If you didn't include pass after a function with no definition you would get an error:
"IndentationError: expected an indented block"
leaving pass at the end of your function definition will have no effect on your function.