What is function in python?
A function is a block code that takes in some data and either performs some kind of transformation and returns the transformed data or performs some task on data or both.
Parts of function:-
- Keyword def()- This is the keyword used to say that a function will be defined now.
- Function name- This is the name that is used to identify the function. The function name comes after the def keyword.
- Parameter list- Parameter list are placeholders that define the parameters that go into the function. In python, parameters are enclosed in parentheses
- Function docstring- These are optional constructs that provide a convenient way for associated documentation to the corresponding function. Docstrings are enclosed by triple quotes.
- Function returns- Python function return a value.
def name_of_function(arguments): """docstring""" body of function return the value of function
Indentation is very important part of function in python.
def hello_world(): print("Hello, World!) hello_world():
Please login to comment
View all comments