def
keyword.def
keyword followed by the function name and parentheses ()
.return
statement to send a value back to the caller.Syntax:
Example:
()
.Example:
Example:
Positional Arguments: Arguments are passed in the order of parameters.
Keyword Arguments: Arguments are passed with the parameter name.
Default Arguments: Parameters have default values if no argument is provided.
Variable-Length Arguments:
*args
: Accepts any number of positional arguments as a tuple.**kwargs
: Accepts any number of keyword arguments as a dictionary.Example:
return
statement is used to send a value back to the caller.Example:
global
keyword to modify a global variable inside a function.Example:
lambda
keyword.Syntax:
Example:
Simple Function:
Function with Default Argument:
Function with Variable-Length Arguments:
Lambda Function: