w3resource

How do you call a function in Python? Give an example.

Calling Python functions: A simple guide with Example

Python calls a function by using its name followed by parentheses containing any required arguments or parameters. A function can be called by writing its name, followed by parentheses with any variables or values it requires. Here's an example of how to call a function in Python:

Code:

# Function definition
def message(name):
    return f"Hello, {name}!"
# Call the function
def message(name):
    return f"Hello, {name}!"

# Function call
result = message("Norah")

# Printing the result
print(result)  # Output: Hello, Norah!
result = message("Norah")
# Printing the result
print(result)  # Output: Hello, Norah!

In the above example, we defined a function called "message" that takes one parameter 'name'. The function returns a message with the provided name. To call the "message" function, we pass the argument "Norah" inside the parentheses, and it returns the result "Hello, Norah!". The result is then stored in the variable result and printed.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-interview/how-do-you-call-a-function-in-python.php