class LittlePractice():
def fibonacci(self,fib: int) -> list:
"""Fibonacci series:the sum of two elements defines the next
:return:Fibonacci list
"""
a, b = 0, 1
fib_list = []
while a < fib:
fib_list.append(a)
a, b = b, a + b
return fib_list
def learn_match(self):
pass
def un_packing_list(self,list1:list):
"""*-operator to unpack the arguments out of a list or tuple
"""
return list(range(*list1))
def un_packing_dict(self,name,age,tele):
"""dictionaries can deliver keyword arguments with the **-operator
"""
return 'My name is ' + name + '.I am ' + str(age) + ' years old.My telephone number is ' + tele + '.'
def learn_lambda1(self,n):
"""lambda functions can reference variables from the containing scope
"""
return lambda x:x+n
def learn_lambda2(self):
"""pass a small function as an argument
"""
pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
pairs.sort(key=lambda pair: pair[1])
print(pairs)
practice = LittlePractice()
print(practice.fibonacci(fib=10))
print(practice.un_packing_list(list1 = [1,5]))
d = {'name':'Tom','age':15,'tele':'110'}
print(practice.un_packing_dict(**d))
f = practice.learn_lambda1(50)
print(f(100))
practice.learn_lambda2()
|