Question : Why doesn't example[999:9999] result in error? Since example[999] does, what is the motivation behind it?
Answer :
- [999:9999] isn't an index, it's a slice, and has different semantics. From the python intro : "Degenerate slice indices are handled gracefully : an index that is too large is replaced by the string size, an upper bound smaller than the lower bound returns an empty string"
- The slice of s from i to j is defined as the sequence of items with index k such that i <= k < j. If i or j is greater than len(s), use len(s).
Source :
'Language > Python' 카테고리의 다른 글
[unittest] Unit Testing Our Code (0) | 2022.10.16 |
---|---|
[Syntax] Special arguments *args and **kwargs (0) | 2022.10.14 |
[os] User Underlying Operating System (1) | 2022.10.03 |
[sys] The way to import module not found (0) | 2022.10.03 |
[OOP] Implement Logic Gates using Class Inheritance (0) | 2022.10.03 |