-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfunctions.py
More file actions
88 lines (51 loc) · 1.31 KB
/
functions.py
File metadata and controls
88 lines (51 loc) · 1.31 KB
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
79
80
81
82
83
84
85
86
87
88
# function - block of code
# basic function
def magacaFun():
print("Hello World")
# Pass
def magacaFun():
pass
# Arguments
def salam(name):
print("ASC", name)
salam("Duraan")
def add(x):
print(10 * x)
add(5)
# Multiple Arguments
def salam(first_name, last_name):
print("ASC", first_name, last_name)
salam("duraan", "ali")
# Arbitrary Arguments (Args)
def myKids(*kids):
print("My youngest kid is " + kids[0])
myKids("Nasteexo", "Uthmaan")
# Keyword Arguments (Kwargs)
def myKids(child1, child2):
print("My youngest kid is " + child2)
myKids(child1 = "Nasteexo", child2 = "Uthmaan")
# Arbitrary Keyword Arguments (**Kwargs) - DICT
def kids(**kids):
print("her first name is " + kids["first_name"])
print("her last name is " + kids["last_name"])
kids(first_name = "Nasteexo", last_name = "Ahmed")
# Return Value
def fun1(x, y):
return y * x
print(fun1(7, 8))
#default Parameter
def wadan(wadan = "Somalia"):
print("I am from " + wadan)
wadan()
# Lambda Function/Expressions - SMALL ANONYMOUS FUNCTION
# lambda argument : expression
x = lambda a: a + 10
print(x(5))
# Multiply
x = lambda a, b: a * b
print(x(9, 10))
# Power of Lambda: Function within function
def myFun(n):
return lambda a: a * n
double = myFun(3)
print(double(10))