Beginner LevelPython
What is the difference between pass and Ellipsis (...) as code placeholders or stub bodies?
❓ Interview Prompt: Compare `pass` (null statement doing nothing) vs `Ellipsis` (`...` built-in singleton object used as type hint stub or NumPy slice).
1. 'pass':
•
A null statement placeholder. Does nothing at runtime; inserted where syntax requires a statement.
2. Ellipsis ('...'):
•
A built-in singleton object in Python.
•
Used as code stubs in function signatures/type hints ('def foo() -> None: ...').
•
Extensively used in NumPy for multidimensional array slicing ('matrix[..., 0]').
Code Implementation Example
python
# 1. pass used as empty block
class EmptyClass:
pass
# 2. Ellipsis (...) used as stub method
def abstract_handler() -> None:
... # Valid syntax in Python!💡Using pass and Ellipsis (...) as code placeholders.
🎯 Interview Key Takeaway
Use pass for empty statement blocks and Ellipsis (...) for function stubs and NumPy multidimensional slicing.
#pass#Ellipsis#...#Beginner
Back to all Python Questions→