defis_prime(num):'''
Naive method of checking for primes.
'''for n inrange(2,num):if num % n ==0:print(num,'is not prime')breakelse:# If never mod zero, then primeprint(num,'is prime!')
lambda
#MAP
my_nums =[1,2,3,4]list(map(lambda num: num **2, my_nums))defsquare(x):return x**2list(map(square, mylist))# [1,4,9,16]list(filter(lambda n: n %2==0,my_nums))defcheck_even(x):return x%2==0list(filter(check_even, mylist))# [2,4]
args-and-kwargs
defmyfunc(*args):returnsum(args)*.05
myfunc(40,60,20)# 6.0defmyfunc(**kwargs):if'juice'in kwargs:print(f"May I have some {kwargs['juice']} juice?")else:pass
myfunc(juice='orange')# May I have some orange juice?
A personal blog by Volkan Uyarer. Developer, Lifelong Learner, Tech Enthusiast.