You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `else` clause after try block is also called "completion clause" as reaching the `else` clause in a `try` statement means that the try block actually completed successfully.
2204
2204
2205
2205
---
2206
+
### ▶ Ellipsis ^
2207
+
2208
+
```py
2209
+
def some_func():
2210
+
Ellipsis
2211
+
```
2212
+
2213
+
**Output**
2214
+
```py
2215
+
>>> some_func()
2216
+
# No output, No Error
2217
+
2218
+
>>> SomeRandomString
2219
+
Traceback (most recent call last):
2220
+
File "<stdin>", line 1, in <module>
2221
+
NameError: name 'SomeRandomString' is not defined
2222
+
2223
+
>>> Ellipsis
2224
+
Ellipsis
2225
+
```
2226
+
2227
+
#### 💡 Explanation
2228
+
- In Python, `Ellipsis` is a globally available builtin object which is equivalent to `...`.
2229
+
```py
2230
+
>>> ...
2231
+
Ellipsis
2232
+
```
2233
+
- Eliipsis can be used for several purposes,
2234
+
+ As a placeholder for code that hasn't been written yet (just like `pass` statement)
2235
+
+ In slicing syntax to represent the full slices in remaining direction
So our `three_dimensional_array` is an array of array of arrays. Let's say we want to print the second element (index `1`) of all the innermost arrays, we can use Ellipsis to bypass all the preceding dimensions
2252
+
```py
2253
+
>>> three_dimensional_array[:,:,1]
2254
+
array([[1, 3],
2255
+
[5, 7]])
2256
+
>>> three_dimensional_array[..., 1] # using Ellipsis.
2257
+
array([[1, 3],
2258
+
[5, 7]])
2259
+
```
2260
+
Note: this will work for any number of dimensions. You can even select slice in first and last dimension and ignore the middle ones this way (`n_dimensional_array[firs_dim_slice, ..., last_dim_slice]`)
2261
+
+ In [type hinting](https://docs.python.org/3/library/typing.html) to indicate only a part of the type (like `(Callable[..., int]` or `Tuple[str, ...]`))
2262
+
+ You may also use Ellipsis as a default function argument (in the cases when you want to differentiate between the "no argument passed" and "None value passed" scenarios).
0 commit comments