|
| 1 | +# This file gives demo about functions |
| 2 | + |
| 3 | +deffunction_with_arg(arg1,arg2="Pooja"): |
| 4 | +print("Value of arg1 ",arg1) |
| 5 | +print("Value of arg2 ",arg2) |
| 6 | +print("*"*25) |
| 7 | + |
| 8 | + |
| 9 | +print("Calling function_with_arg with one parameter") |
| 10 | +function_with_arg("Rohit") |
| 11 | + |
| 12 | +print("Calling function_with_arg with two parameter values") |
| 13 | +function_with_arg("Rohit","Phadtare") |
| 14 | + |
| 15 | +# calling function with arguments name |
| 16 | +print("Calling function_with_arg with argument name") |
| 17 | +function_with_arg(arg2="Rohit",arg1="Phadtare") |
| 18 | + |
| 19 | + |
| 20 | +deffunction_var_arg_demo(*args): |
| 21 | +print("Inside function_var_arg_demo...") |
| 22 | +cnt=1 |
| 23 | +foriinargs: |
| 24 | +print("param{} value is {} ".format(cnt,i)) |
| 25 | +cnt+=1 |
| 26 | + |
| 27 | +print("*"*25) |
| 28 | + |
| 29 | + |
| 30 | +function_var_arg_demo("Rohit","Prakash","Phadtare") |
| 31 | + |
| 32 | + |
| 33 | +deffunction_var_karg_demo(**kargs_list): |
| 34 | +print("Inside function_var_karg_demo...") |
| 35 | +cnt=1 |
| 36 | +forparam_name,param_valueinkargs_list.items(): |
| 37 | +print("{} value is {} ".format(param_name,param_value)) |
| 38 | +cnt+=1 |
| 39 | + |
| 40 | +print("*"*25) |
| 41 | + |
| 42 | + |
| 43 | +function_var_karg_demo(first_name="Rohit",middle_name="Prakash",last_name="Phadtare") |
| 44 | + |
| 45 | + |
| 46 | +deflambda_func_demo(input_list): |
| 47 | +print("Inside lambda_func_demo .. ") |
| 48 | +print("Given list : ",input_list) |
| 49 | + |
| 50 | +list_even_num=list(filter(lambdan: (n%2==0),input_list)) |
| 51 | + |
| 52 | +print("Filtered list with even values : ",list_even_num) |
| 53 | +print("*"*25) |
| 54 | + |
| 55 | + |
| 56 | +lambda_func_demo(range(10,21)) |