I don't have enough experience to compare with anything, ** Python error messages are concrete and easy to understand ** I feel that. Therefore, the error can be read not only at a glance but also seriously. I feel that it is a shortcut for error resolution.
However, there are times when I don't understand for a moment, so ** Let's calm down on the assumption that you should understand ** This is an article to show such feelings.
The meaning of Index Error: list index out of range ** in the supplementary ** element [0] is When it is said that it is out of range, why is element [0] out of range? is what it means.
The code shown here is for issuing an error message. It's not code that can make exactly the same mistakes. I repeat. This is the code to issue an error message. (However, I've seen the same error in a slightly more confusing code.)
** IndexError: list index out of range ** is displayed. The code is below. The code below doesn't make sense, (However, in the following, if b is ** getting a list by the return value of the function **, I think that you may meet.)
index_err1.py
a = [1, 2, 3]
b = []
print("a[0]",a[0])
print("b[0]",b[0])
The error display is as follows.
Traceback (most recent call last):
File "list_err1.py", line 5, in <module>
print("b[0]",b[0])
IndexError: list index out of range
Listing b just says it doesn't even [0], Again, I don't write this code, In many cases, b gets a list from the return value of the ** function. **I thought.
** IndexError: list index out of range ** should be set unless the Index is specified incorrectly. There are cases where the original object is not created properly. ** In many cases, such as when you get a list by the return value of a function. ** **
I think it's a natural result in terms of composing the error message, but I felt it was easy to understand. .. ..
Use python without stress! (Become familiar with generator. It seems to be since1975.)
Use python without stress! (In Python, everything is implemented as an object) Use python without stress! (Close to Pylint) Use python without stress! (Expression and Statement) Learn Python carefully using both English and Japanese.
If you have any comments, please let us know. : candy: Will study,,,,
Recommended Posts