如何在 struct 上匹配PYTHON中的内置类型切片?
以下代码不起作用的原因如下:
def __getitem__(self, index):
match index:
case int(i):
...
case slice(start, stop, step):
...
case _:
...
我完全不明白为什么.
如何在 struct 上匹配PYTHON中的内置类型切片?
以下代码不起作用的原因如下:
def __getitem__(self, index):
match index:
case int(i):
...
case slice(start, stop, step):
...
case _:
...
我完全不明白为什么.
try :
class Example:
def __getitem__(self, index):
match index:
case int(i):
print('int', i)
case slice(start=start, stop=stop, step=step):
print('slice', start, stop, step)
case _:
print('default')
e = Example()
e[1]
e[1:2]
打印:
int 1
slice 1 2 None