Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is a pass statement in Python?

221910308019

A pass statement is an empty/null statement that is considered as a placeholder for future code. When a user doesn’t want to write a code, or is not able to write a code under a particular class or function, the user can apply a pass statement.

Empty code shouldn’t be included in loops, function definitions, class definitions, or if statements because there is a possibility that it will cause an error. To avoid errors, the user can simply apply a pass statement.

Code

In the code snippet below, our code is in the else block, but because of the pass statement, no operation is performed.

Remember: The pass statement is a placeholder for future code; so, we can replace it whenever we have to do an operation in this else block.

lst = [1, 2, 3]
value = 5

if value in lst:
  print('Its in the list')
else:
  pass

print('Execution completed')

RELATED TAGS

python
communitycreator
RELATED COURSES

View all Courses

Keep Exploring