मराठी

Does a function always return a value? Explain with an example. - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Does a function always return a value? Explain with an example.

थोडक्यात उत्तर
Advertisements

उत्तर

A function does not always return a value. In a user-defined function, a return statement is used to return a value.

Example:

Program:
# This function will not return any value
def func1():
    a = 5
    b = 6

# This function will return the value of 'a' i.e. 5
def func2():
    a = 5
    return a

# The return type of the functions is stored in the variables
message1 = func1()
message2 = func2()

print("Return from function 1-->", message1)
print("Return from function 2-->", message2)


​​OUTPUT:
Return from function 1--> None
Return from function 2--> 5
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 7: Functions - Exercise [पृष्ठ १७०]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 11
पाठ 7 Functions
Exercise | Q 7. | पृष्ठ १७०
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×