Classification of Functions in Python
Classify Functions Based on Arguments and Return Values
In Python, functions are classified into four types based on whether they accept arguments and return values:
1. No Arguments, No Return Value
- These functions do not take any input and do not return any output.
- Used when the function performs a task like displaying a message.
Example:
def greet():
print("Hello!")
greet()
2. Arguments, No Return Value
- These functions take arguments but do not return any value.
- Used when data is passed to the function, and only internal processing or display is needed.
Example:
def greet(name):
print("Hello", name)
greet("Ravi")
3. No Arguments, Return Value
- These functions do not take any input but return a value.
- Useful when the function generates or fetches data without external input.
Example:
def get_number():
return 100
x = get_number()
4. Arguments and Return Value
- These functions accept input arguments and return a result.
Classification of Functions in Python
- Most commonly used type for calculations or data processing.
Example:
def add(a, b):
return a + b
sum = add(10, 20)
Conclusion:
These four types allow flexibility in function usage depending on the need for inputs and outputs. Proper use helps in
modular, reusable, and clean code design.