Skip to Content
Python🤔 What the Python! Lạ thế nhỉ?Ellipsis ... - Không chỉ để slicing

Ellipsis … - Không chỉ để slicing

Ellipsis là gì?

# Ellipsis là built-in constant print(...) # Ellipsis print(type(...)) # <class 'ellipsis'> print(Ellipsis) # Ellipsis print(... is Ellipsis) # True

Use cases

1. Placeholder code

def not_implemented_yet(): ... # Tương tự pass class MyClass: ... # Empty class

2. Type hints

from typing import Callable # Function với bất kỳ args nào func: Callable[..., int] # Args bất kỳ, return int

3. NumPy slicing

import numpy as np arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) # ... = as many : as needed print(arr[..., 0]) # Tương đương arr[:, :, 0]

Tóm tắt

Ellipsis ...:

  • Built-in constant
  • ✅ Placeholder thay pass
  • ✅ Type hints
  • ✅ NumPy slicing

Pattern:

def todo(): ... # Placeholder
Last updated on