["python"]
If list index exists, do X

I need to code such that if a certain list index exists, then run a function. My failing code: n = int(input("Define number of actors: ")) count = 0 nams = [] while count < n: count = count + 1 print("Define name for actor", count, ":") nams.append(input()) if nams[2]: # 'if nams[2] exists, do something depending on len(nams) if len(nams) > 3: do_something
Could it be more useful for you to use the length of the list len(nams) to inform your decision rather than checking nams[i] for each possible length?