Show code
# define function
def greet(name):
print(f"Hello, {name}!")
# calling function
greet("Gujuri Alekha")Hello, Gujuri Alekha!
Gujuri Alekha
Oct 20, 2024
Defining a Function : A function in Python is a reusable block of code that performs a specific task. To define a function, you use the def keyword followed by the function name and a pair of parentheses.
Calling a Function : Once a function is defined, you can call it by using its name followed by parentheses, passing any required arguments (if any).
Function Arguments: Functions can accept input values called arguments or parameters. These values are passed into the function when it’s called and can be used inside the function.
Return Values : Functions can also return values using the return statement. A function can return one or multiple values.
square root of 16 is : 4.0
square root of 49 is : 7.0
Get new notebooks as they're published
New parts are added to each track in order. Follow along:
@online{alekha2024,
author = {Alekha, Gujuri},
title = {Python {Functions} and {Modules}},
date = {2024-10-20},
url = {https://gujurialekha.github.io/blog/python/03-python-functions-and-modules.html},
langid = {en}
}