+ 1
help me what is def in python fully plz??
Full of ????
2 Respostas
+ 3
Def: is the keyword to define a function in python. Example;
def add(a,b):
return a+b
0
It defines a block of code, which will be ran only when the function is called.
Function definition:
def f(args):
~code~
Function call:
f(args)
Where:
f is the function name, function names follow variable naming rules.
args is a list of names (parameters), such as (x, y, z).
When the function is called, each name should get a corresponding argument (value). And then the parameters can be used as variables in the function code.
~code~ can be just basic code, which will only be normally ran when the function is called. It can include a return statement, which will break the function call and return a value to the place where the function was called.