Questions

What is Function in Python with Example?

function in python refers to a block of code that can be reused to perform the same task. Functions allow breaking your program into modules. A function runs only after you call it. You can pass parameters and arguments in the function. A few examples are-

Syntax: 

                    

def test_function():

  print("Hello! I hope you are doing fine")

Output:

                    

Hello! I hope you are doing fine

Syntax:

                    

def my_function(firstname):

  print(fname + " Weasley")



my_function("Fred")

my_function("Ron")

my_function("Ginny")

Output:

                    

Fred Weasley

Ron Weasley

Ginny Weasley

Here the argument that is being passed as an argument in the function is being concatenated with the string “Weasley”.

Related Questions

Related Topics

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.