-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path#16-function.py
78 lines (42 loc) · 1.4 KB
/
#16-function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#function in python
# function always defined with 'def' keyword
def myFunction():
print("hello World from python")
myFunction()
# with arguments
# you have to pass all the parameter that defines not more or less than that
# with default parameter
def My_arg_function(fname='john'):
print(fname + '@gmail.com')
# the arguments will be pass as a paramter to the function calling
My_arg_function("open269")
# Aribitary arguments
# when you don't know the parameter count will be passed
# if the value is less than than the
def myariFun(*kids):
print("the Young kids is " + kids[1])
myariFun("jhon", "mosh", "beauty")
# keyword arguments
def Keyword_args(child1, child2):
print("the youngest child " + child2)
Keyword_args(child1="jhon", child2="moshi")
# Aribitary arg
def ar_Keyword_args(**kid):
print("your last name " + kid["lname"])
ar_Keyword_args(fname='jhon', lname='doe')
def list_func(food): # passing list as a param
for x in food:
print(x)
list_func(['jam', 'bread', 'rice'])
# returning value
def addition(fnum, lnum):
return fnum + lnum
print(addition(2, 6))
# Recursion
# recursion is a popular thing that can used as a back self calling function
# so we have to first call the factotial of 5 so we have to know the factorial of 4 and thing chain is going till 0
def fact(k):
if k == 0:
return 1
return k * fact(k-1)
print(fact(5))