Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

02 Functions

The document discusses Python functions including defining functions with parameters and return values, calling functions, and using functions like add() and exclamify() which adds exclamation points to text. Various examples demonstrate defining and calling functions to perform calculations and string manipulations.

Uploaded by

Alex s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

02 Functions

The document discusses Python functions including defining functions with parameters and return values, calling functions, and using functions like add() and exclamify() which adds exclamation points to text. Various examples demonstrate defining and calling functions to perform calculations and string manipulations.

Uploaded by

Alex s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

1

2
3
♀ ♀ ♀ ♂ ♀ ♂ ♂ ♀ ♂ ♂ ♀

4
5
'a' + 'hoy'
'ahoy'

6
2 44 -3
3.14 4.5 -2.0
True False
'¡hola!' 'its python time!'

7
18 + 69

6/23

2 * 100

2 ** 100

8
pow(2, 100)

max(50, 300)

min(-1, -300)

9
2 ** 100
pow(2, 100)

10
2 ** 100
pow(2, 100)

from operator import add

18 + 69
add(18, 69)

pow()
add() div()
operator

10
add ( 18 , 69 )

11
add ( 18 , 69 )

11
add ( 18 , 69 )

11
add ( 18 , 69 )

11
add ( 18 , 69 )

11
add(add(6, mul(4, 6)), mul(3, 5))

12
add(add(6, mul(4, 6)), mul(3, 5))

add

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add 6 mul(4, 6)

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add 6 mul(4, 6)

mul

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add 6 mul(4, 6)

mul 4

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add 6 mul(4, 6)

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add 6 mul(4, 6)

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6))

add 6 mul(4, 6)

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6)) mul(3, 5)

add 6 mul(4, 6)

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6)) mul(3, 5)

add 6 mul(4, 6) mul

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6)) mul(3, 5)

add 6 mul(4, 6) mul 3

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6)) mul(3, 5)

add 6 mul(4, 6) mul 3 5

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6)) mul(3, 5)

add 6 mul(4, 6) mul 3 5

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6)) mul(3, 5)

add 6 mul(4, 6) mul 3 5

mul 4 6

12
add(add(6, mul(4, 6)), mul(3, 5))

add add(6, mul(4, 6)) mul(3, 5)

add 6 mul(4, 6) mul 3 5

mul 4 6

12
13
14
x = 7

15
x = 7

x = 1 + 2 * 3 - 4 // 5

15
x = 10
y = 3

result1 = x * y
result2 = x + y

16
x = 10
y = 3

result1 = x * y
result2 = x + y

16
my_name = 'Pamela'

my_name = my_name + 'ela'

my_name

17
my_name = 'Pamela'

my_name = my_name + 'ela'

my_name

my_name

17
f = min
f = max
g = min
h = max
max = g
max(f(2, g(h(1, 5), 3)), 4)

18
19
20
=

21
22

add(18, 69)
mul(60, sub(5, 4))

23

add(18, 69)
mul(60, sub(5, 4))

18, 69 → add → 87

23
def

def <name>(<parameters>):
return <return expression>

def add(num1, num2):


return num1 + num2

add(2, 2)
add(18, 69)

24
def <name>(<parameters>): # ← Function signature
return <return expression> # ← Function body

def add(num1, num2): # ← Function signature


return num1 + num2 # ← Function body

25
def <name>(<parameters>): # ← Function signature
return <return expression> # ← Function body

def add(num1, num2): # ← Function signature


return num1 + num2 # ← Function body

def add(num1, num2): # ← Function signature


sum = num1 + num2 # ← Function body
return sum # ← Function body

25
def add(num1, num2):
return num1 + num2

x = 1
y = 2
add(x, y)

x = 3
add(x * x, x + x)

26
def add(num1, num2):
return num1 + num2

sum = add(2, 4)

big_sum = add(200, 412) + add(312, 256)

huge_sum = add(add(200, 412), add(312, 256))

27
def add(num1, num2):
return sum
sum = num1 + num2

sum = add(2, 4)

28
def add(num1, num2):
return sum
sum = num1 + num2

sum = add(2, 4)

28
def add():
return num1 + num2

sum = add(2, 4)

29
def add():
return num1 + num2

sum = add(2, 4)

29
def add(num1, num2):
sum = num1 + num2

sum = add(2, 4)

30
def add(num1, num2):
sum = num1 + num2

sum = add(2, 4)

30
name parameters

31
32
33
34
35
def exclamify(text):
start_exclaim = "¡"
end_exclaim = "!"
return start_exclaim + text + end_exclaim

exclamify("the snails are eating my lupines")

start_exclaim

text

exclamify

36
def exclamify(text):
start_exclaim = "¡"
end_exclaim = "!"
return start_exclaim + text + end_exclaim

exclamify("the snails are eating my lupines")

start_exclaim

text

exclamify

36
def exclamify(text):
start_exclaim = "¡"
end_exclaim = "!"
return start_exclaim + text + end_exclaim

exclamify("the snails are eating my lupines")

start_exclaim

text

exclamify

36
def exclamify(text):
start_exclaim = "¡"
end_exclaim = "!"
return start_exclaim + text + end_exclaim

exclamify("the snails are eating my lupines")

start_exclaim

text

exclamify

36
start_exclaim = "¡"
end_exclaim = "❣️"

def exclamify(text):
return start_exclaim + text + end_exclaim

exclamify("the voles are digging such holes")

start_exclaim

text

exclamify

37
start_exclaim = "¡"
end_exclaim = "❣️"

def exclamify(text):
return start_exclaim + text + end_exclaim

exclamify("the voles are digging such holes")

start_exclaim

text

exclamify

37
start_exclaim = "¡"
end_exclaim = "❣️"

def exclamify(text):
return start_exclaim + text + end_exclaim

exclamify("the voles are digging such holes")

start_exclaim

text

exclamify

37
start_exclaim = "¡"
end_exclaim = "❣️"

def exclamify(text):
return start_exclaim + text + end_exclaim

exclamify("the voles are digging such holes")

start_exclaim

text

exclamify

37
def exclamify(text):
end_exclaim = "⁉️️"
return start_exclaim + text + end_exclaim

exclamify("the voles are digging such holes")

NameError

38
def exclamify(text):
end_exclaim = "⁉️️"
return start_exclaim + text + end_exclaim

exclamify("the voles are digging such holes")

NameError
start_exclaim

38
def exclamify(text):
end_exclaim = "⁉️️"
return start_exclaim + text + end_exclaim

exclamify("the voles are digging such holes")

NameError
start_exclaim

exclamify

38
39
40

You might also like