判断一个对象是否能够进行迭代的方法 Iterable
from collections import Iterable dict = {'name':'Joe','age':17} print (isinstance(dict,Iterable))
print (isinstance('1232ksd',Iterable))
print (isinstance(1232,Iterable)) print (type(dict)) #遍历字典的方法
for key in dict:
print (key,dict[key]) for k,v in dict.items():
print (k,v) for value in dict.values():
print (value) #请使用迭代查找一个list中最小和最大值,并返回一个tuple Li = [5,465,66,11,-45,54,999]
print (type(Li))
print (isinstance(Li,Iterable)) def findMinMax(L):
min = 0
max = 0
for c in L:
if c > max:
max=c
if c < min:
min=c
return(min,max) findMinMax(Li) print (type(findMinMax(Li)))