Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to "call" a function in Python? [closed]

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

like image 854
user2837438 Avatar asked Oct 02 '13 06:10

user2837438


People also ask

What does it mean to call a function Python?

00:05 To call a function—to use a function, or invoke, are other terms that we use—you simply give the name of the function and then, followed in parentheses, argument values—if any—that are needed.

How do you close a function in Python?

A return statement effectively ends a function; that is, when the Python interpreter executes a function's instructions and reaches the return , it will exit the function at that point.

What is the correct way to call a function in Python?

Once we have defined a function, we can call it from another function, program, or even the Python prompt. To call a function we simply type the function name with appropriate parameters. >>> greet('Paul') Hello, Paul.

What does it mean by calling a function?

When you call a function you are telling the computer to run (or execute) that set of actions. A function definition can be provided anywhere in your code - in some ways the function definition lives independently of the code around it. It actually doesn't matter where you put a function definition.


1 Answers

When you "call" a function you are basically 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 would call the function like this:

add(3,5)

which would 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 would set the variable answer equal to 11 in this case.

like image 169
Joel Green Avatar answered Oct 19 '22 00:10

Joel Green