# Iteration # If given a list or tuple, we can traverse the list or tuple through a for loop, which we call an iteration (iteration) # in Python, the iteration is through the for ... in, and in many languages such as C or Java, the iteration list is a high abstraction of the # python for loop done by subscript, because Python's for loop can be used not only on list or tuple, It is also possible to # iterations on other iterative objects dict# because Dict's storage is not arranged in list order, the resulting order of the iterations is likely to be different # by default dict iterations key# If you want to iterate over value, you can use For value in d.values () # If you want to iterate both key and value at the same time, you can use the For k, v in d.items () # determines that an object is an iterative object by the iterable type of the collection module from collections import iterabled = {' A ': 1, ' B ': 2, ' C ': 3}print (' iterative key ') for key in d: print (key) print (' Iteration value ') for value in d.values (): Print (value) print (' Iterative key&value ') For k, v in d.items (): print (K,  V) # Iteration string print (' Iteration string ') for ch in ' ABC ': print (CH) # Whether Str can iterate print (isinstance (' abc ', &NBSP, iterable)) # list whether the print (Isinstance ([1, 2, 3], iterable)) # integer can be iterated by the print (isinstance (123, iterable)) # uses Python's built-in enumerate function to turn a list into an index-element pair that iterates through both the index and the element itself in the For loop for i, value in enumerate ([' A ', ' B ', ' C ']): print (I, value)
Python---Iteration