Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (20.3k points)

What does "call" mean and do? How would you "call" a function in Python?

2 Answers

0 votes
by (40.7k points)

When we  "call" a function we are generally just telling the program to execute that function. So if you had a function that added two numbers such as:

def add(a,b):

    return a + b

you can also call the function like this:

add(3,5)

Which will return 8. You can put any two numbers in the parentheses in this case. You can also call a function like this:

answer = add(4,7)

Which will set the variable answer equal to 11 in this case.

0 votes
by (106k points)

To "call" means to make a reference in your code to a function that is written elsewhere. This function "call" can be made to the standard Python library (stuff that comes installed with Python), third-party libraries (stuff other people wrote that you want to use), or your own code (stuff you wrote). For example:

#!/usr/env python 

import os 

def foo(): 

return "hello world" 

print os.getlogin() 

print foo()

Related questions

0 votes
4 answers
0 votes
1 answer
asked Oct 8, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Mar 22, 2021 in Python by Rekha (2.2k points)
0 votes
1 answer

Browse Categories

...