+ 2
Pls i need simplified explanation on FUNCTIONAL PROGRAMMING A.S.A.P
PLS JUST EXPLAIN IT TO ME IN A SIMPLIFIED MANNER. thanks!!!
1 ответ
0
You take something specific:
I want to add 2+2
You write the code:
print(2 + 2)
4
Cool, what if i want to add any two numbers though...?
Okay, so obviously I will need two numbers as parameters. This is where the function comes in. Its just taking a problem and generalizing it.
def add2nums(x,y): #call it whatever
print(x + y) #using our parameters
So now weve defined our function. But nothings happening...
Call that function out!
add2nums(4,5)# <-- x and y == 4 and 5
9
Now instead of only being able to add 2 and 2, you can throw any two numbers in there and it will add them up. This is overly simple but shows a function in action