This is a repeatable object, and I have a question
a = [1,2,3,4]
for i in a: print(a)
b = iter(a)
for i in b: print(b)
We use the ether function to call up the value one by one, but isn't the conclusion the same? I don't know the value using the ether function except for one time. Is there a way to load the value using next()
without a repeat statement?
If you insist on using iter() in the example you presented, you should do it as follows.
a = [1,2,3,4]
b = iter(a)
for i in b:
print(i)
To answer your question, you can use the following format.
a = [1,2,3,4]
b = iter(a)
while b:
print b.next()
# The StopIteration excitation processing is omitted.
© 2024 OneMinuteCode. All rights reserved.