Last answered:

02 Sept 2023

Posted on:

27 Feb 2023

1

Resolved: Concering about the function named "def"

I just want to ask what function def is and what does it do?

3 answers ( 2 marked as helpful)
Posted on:

01 Mar 2023

2

Hi John

I hope you're well

the word "def" in python is used to name your custom function. For example:

You want to create a function that multiplies a number by 2, so you write in your program 

def multby2(int):

             int * 2


then, when you want to use the function have to indicate for example:

multby2(5)

print(multby2(5))

and after the execution, you going to see the multiplication complete 

10

you can check the next link for a better explanation

https://realpython.com/defining-your-own-python-function/


I hope this could be help

Posted on:

16 Aug 2023

0

I'm lost on this particular exercise...print (five(3)) equals 5? I don't know what the '3' is doing (how it affects anything) at all in this code. I guess I don't understand what the command 'print (five(3))' is supposed to do.

Posted on:

02 Sept 2023

2

@Matt I think you will get how it works as you get to the functions part but in short, the 3 there is to show that no matter what input you pass (not just 3, it can be 49, 87 etc..), the function will just spit out five since the function does the job of assigning value "5" inside.

Submit an answer