Message402577
The `TypeError` message when a string is indexed using a string should be similar to the `TypeError` message when a list or tuple is indexed using a string.
>>> my_str = 'Rin'
>>> my_str[1:3] # works
'in'
>>> my_str['no']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string indices must be integers
>>> my_str[slice(1, 3)] # works with slices
'in'
Certainly it does work with slice as intended but the error message should explain that, as seen in the following
>>> my_list = [1, 2, 3]
>>> my_list['no']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers or slices, not str
>>> my_tuple = (1, 2, 3)
>>> my_tuple['no']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: tuple indices must be integers or slices, not str
The error message shows `slices` are indeed an option to use when indexing a list or tuple.
Would be happy to submit a documentation PR if this minor change would be accepted. |
|
Date |
User |
Action |
Args |
2021-09-24 16:33:24 | Rin | set | recipients:
+ Rin |
2021-09-24 16:33:24 | Rin | set | messageid: <1632501204.02.0.12612984159.issue45284@roundup.psfhosted.org> |
2021-09-24 16:33:24 | Rin | link | issue45284 messages |
2021-09-24 16:33:23 | Rin | create | |
|