Forum in maintenance, we will back soon 🙂
python fuctions.
Defining a Function
Here’s how you define a function:
Let’s define a function named greet
That prints a greeting:
Calling a Function
After defining a function, you can call it by its name followed by parentheses. Let’s call our greet
function:
Functions with Parameters
Sometimes, we want our function to perform an operation on a variable. We can achieve this by defining a function with the parameters:
Now, when we call the greet
Function, we need to provide a name:
Functions that Return Values
Sometimes, we want our function to give us back a result that we can use later. For this, we use the return
statement:
When we call this function with a number, it gives us the square of that number:
Exercise : Now, your task is to create a function called calculate_average
that takes a list of numbers as an argument and returns their average. Test your function with different lists of numbers to ensure it works correctly.
Here’s a skeleton to get you started:
Hi Jay, the reason I put different examples is to help you understand the concept instead of copying the same code.
I understand that you are not familiar with coding. But if you are looking to learn some skills that really helps you in the future, you should not give up. but I can't oblige you to.
am here to help and explain anything.
Did you understand the concept behind "Functions" in general?
do you know what is a function? and how to declare and call it.
My humble opinion. go again to the first lecture in the python course. and go one by one, and see exactly you are lost, so I can help there. because all concepts are connected and related.
for example; did you understand what is a variable? and what is an operation?
@jay-kim Hey brother I am also new can we connect on WhatsApp and help each other wherever we are stuck? Because waiting for Hasan sir on the forum may take time. What do you say? My WhatsApp number is +91 7000870010.