This question already has an answer here:
I find this behaviour in Python quite peculiar and I believe it can lead to many bugs especially if you have a function/method that takes in a list and returns another list after carrying out some operations on the elements in list.
x =  val = (row for row in x) # create a generator print(next(val)) # will raise StopIteration exception for i in x: if not i: raise ValueError('The sequence is empty') # Exception is not raised print(i) # does nothing and does not raise an exception
If you try to iterate over a generator with
next and it's empty or has reached the end, a
StopIteration exception is raised, but this is not the same when you use a for loop to iterate over a list or any iterable in Python.
I know I could just write
if not x: to check if the list is empty but I believe an empty iterable should raise an Exception when you try to iterate over it as there is no benefit looping it.
I want to know if there's any special reason for this behavior in the Language design or am I not considering another case where it might be useful. I think the same goes for