QA
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→

More Python Interview Questions

Beginner LevelPython

What is the Python Global Interpreter Lock (GIL) and how does it affect multi-threading?

Beginner LevelPython

What is the difference between a List, Tuple, Set, and Dictionary in Python?

Beginner LevelPython

Why are mutable default arguments (like def func(items=[])) dangerous in Python and how do you fix them?