0
Python
I don’t really understand how to use the def function.can someone please explain it?
2 ответов
+ 5
here is a link to a short tutorial from sololearn:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2285/?ref=app
+ 4
it is used to define a function, it consists of a piece of code which is designed for completing a certain task
def yourFunctionName(parameters or Arguments):
# your piece of code, written by you
reason behind using a function
it makes our code reusable, because we can call a function from anywhere in our code,
it reduces code length, because we don't have to write same piece of code again and again
for example
def sumTwoNumbers( first, second ):
sum = first + second
now we can call this function any number of times we want
like, print(sumTwoNumbers ( 10, 20))
print(sumTwoNumbers (1000, 3000)