while elem := next(itr)
might not do what is expected if the list that is iterated over contains a None
value: lst = ['foo', 'bar', None, 'baz' ] itr = iter(lst) while elm := next(itr): print(elm)
foo bar
next()
function: #!/usr/bin/python3 # # Open a file for reading # f = open('file.txt') # # Skip a line # next(f) # # Print the remaining lines # for l in f: print(l, end='')