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

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -