Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
Can anyone tell me how to define a function in Python?

1 Answer

0 votes
by (108k points)

Functions or methods are a set of tasks that you want to perform. In Python, you can define a function or a method with a keyword, def.

For instance:

def add(a,b):

return a+b

add(10,20)#calling the user-defined function

Output: 

30

In the above example, I have created a user-defined function named add, and in that method, I have passed two arguments or parameters. The task that I have defined inside the add method is a+b. So, whenever I pass two arguments inside the function, it will perform the task, a+b. Thus, you can see that the output is 30 as I have passed ‘a’ as ‘10’ and ‘b’ as ‘20.’

If you are looking for an online course to learn Python, check out this Python Course by Intellipaat.

Related questions

0 votes
1 answer
asked Jul 14, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 13, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...