Robotics & Artificial Intelligence
Is the return statement mandatory for every function?
Python Functions
1 Like
Answer
No, the return statement is not mandatory for every function. If a function does not contain a return statement, it does not return any value and is called a void (or non-fruitful) function. In such cases, the function returns None automatically.
Answered By
3 Likes
Related Questions
Write a Python program to print the table of a given number by using a function.
Write a Python program to demonstrate the concept of default arguments in a function.
Write a function that returns the greater of two numbers passed as arguments.
Write a function called ice_water that takes a number as input. Perform the following operations:
- If the number is divisible by 3, then it should return "ice".
- If it is divisible by 5, then it should return "water".
- If it is divisible by both 3 and 5, then it should return "icewater".
- Otherwise, it should return the same number.