Built-in Functions 11-20

11.range(n,n2):  from n, but n2 not included.

res = []

for i in range(2700, 3201):

      if (i%7 ==0 ) and (i%5 != 0):

            res.append(str(i))

print(', '. join(res))


12. filter(function,iterable): Construct an iterator from those elements of iterable for which function returns true.

iterable may be either a sequence, a container which supports iteration, or an iterator.

Note that filter(function,iterable) is equivalent to the generator expression (item for item in iterable if function(item)) 

li = [1,2,3,4,5,6,7,8,9,10]


print(list(filter(lambda x: x%2==0, li)))


abs(x) : absolute value of a number

all(iterable): ReturnTrueif all elements of theiterableare true (or if the iterable is empty)

13. map(function, iterable)

list1 = [1,2,3]

return_list = list(map(lambda x:pow(x, 2), list1))

print(return_list)  ###[1,4,9]

14. enumerate(iterable, start=0): returns an enumerating object, which is a tuple or list containing the count (from the number of 'start') and values obtained from the iterating over the 'iterable';

Built-in Functions 11-20_第1张图片
enumerate(literable, start=0)

你可能感兴趣的:(Built-in Functions 11-20)