Python def Keyword
def keyword is used to define user-defined functions. Functions help organize code into reusable blocks, making programs easier to read, maintain, and reuse. They can accept input values through parameters, perform specific tasks and optionally return results.
def func():
print("Hello")
func()
//Hello
def function_name(parameters):
# Code to execute
return value # Optional
function_name: Name of the function.
parameters (optional): input values passed to the function.
return (optional): statement used to send a value back to the caller.
def is a keyword for defining function in python ? True
Function should always return any value?False
Function should always have parameters?False
Error handled in Python till now is:
Indentation Error
Type Error
Syntax Error
Name error
Positional Arguments
Positional arguments mean values are passed in the same order as parameters are defined in the function.The first value goes to the first parameter, second to the second and so on.Changing the order can lead to unexpected results.
def add(a, b):
return a + b
# 5 goes to a, 10 goes to b
print(add(5, 10))
//15
Reference
http://geeksforgeeks.org/python/python-def-keyword/

Top comments (0)