在迭代中enumerate比range更能灵活,一般情况下尽量用erumerate,下面举例说明: 先来看range的使用: city_list = ['beijing', 'shanghai', 'tianjing', 'wuhan'] # 用range将元素打印出来 # 直接打印,不用range for city in city_list: print('this is %s' % city) # 用下标打印 for i in range(len(city_list)): city = ci…
range和xrange的区别 python3里面只有range,返回结果是一个生成器,官方文档是这样描述的 class range(object): """ range(stop) -> range object range(start, stop[, step]) -> range object Return an object that produces a sequence of integers from start (inclusive) to sto…
Help on built-in function range in module __builtin__: range(...) range(stop) -> list of integers range(start, stop[, step]) -> list of integers Return a list containing an arithmetic progression of integers. range(i, j) returns [i, i+1, i+2, ..., j…