python - How to check if end of list was reached? -


if have list, a=[1,2,3], , want see if a[4] null, there way that, without using exception or assertion?

len tell length of list. quote docs:

len(s)
    return length (the number of items) of object. argument may sequence
    (string, tuple or list) or mapping (dictionary).

of course, if want final element in list, tuple, or string, since indexes 0 based, , length of item element count, a[len(a)-1] last item.


as aside, generally, proper way access last element in object allows numeric indexing (str, list, tuple, etc) using a[-1]. obviously, not involve len though.


Comments

Popular posts from this blog

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -

Python __call__ special method practical example -