-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-functions.py
More file actions
40 lines (25 loc) · 841 Bytes
/
6-functions.py
File metadata and controls
40 lines (25 loc) · 841 Bytes
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
# A function is a block of code which only runs when it is called. In Python, we do not use parentheses and curly brackets, we use indentation with tabs or spaces
def sayHello():
print('Hello World')
sayHello()
def sayGoodMorning (name = 'Alfed'):
print('Good mornig ' + name)
sayGoodMorning('Morgan')
sayGoodMorning()
# Return a value
def getSum(num1, num2):
total = num1 + num2
return total
print(getSum(2, 3))
#increment
def addOnetoNum(num):
num =+ 1
return num
print(addOnetoNum(2))
# A lambda function is a small anonymous function.
# A lambda function can take any number of arguments, but can only have one expression. Very similar to JS arrow functions
# Arrow function
getSum = lambda num1, num2 : num1 + num2
print(getSum(9, 2))
addOneToNum = lambda num : num + 1
print(addOneToNum(3))