Q. What is a function? How is it useful?


Answer =

A function in Python is a named block of statements within a program.

For example, the following program has a function within it, namely greet_msg().

# progl.py
def greet msg ():
    print("Hello there!!")
    name = input ("Your name :")
    print (name, greet_msg())

 

• Functions are useful as they can be reused anywhere through their function call statements. So, for the same functionality, one need not rewrite the code every time it is needed, rather through functions it can be used again and again without rewriting the code.

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Function name greet msg is different from greet_msg so it will so error

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post