CBSE Class 12 Computer Science
Question 60 of 103
Working with Functions — Question 7
Back to all questionsThe different styles of functions in Python are as follows :
Built-in functions — These are pre-defined functions and are always available for use. For example:
name = input("Enter your name: ") name_length = len(name) print("Length of your name:", name_length)
In the above example,
print(),len(),input()etc. are built-in functions.User defined functions — These are defined by programmer. For example:
def calculate_area(length, width): area = length * width return area length = 5 width = 3 result = calculate_area(length, width) print("Area of the rectangle:", result)
In the above example,
calculate_areais a user defined function.Functions defined in modules — These functions are pre-defined in particular modules and can only be used when corresponding module is imported. For example:
import math num = 16 square_root = math.sqrt(num) print("Square root of", num, ":", square_root)
In the above example,
sqrtis a function defined in math module.