0

Introduction to Python course

Here, I can't totally get the function part.! 1/what's custom function? Why dowe need it?What's the purpose of it? 2/bmi() function 3/What's return value? Why do we use it? Plz help me out

23rd Dec 2024, 10:20 AM
Rouza TN
Rouza TN - avatar
2 odpowiedzi
+ 3
What's custom function? A custom function is a user defined function, which contains X lines of code. X can be 1 and up to as many as you need. Why do we need it? What's the purpose of it? It makes the code reusable. If your calculation takes a hundred lines of code to get a result, you can make it into a function so it can reuse, without typing the same code again and again. What's return value? You can think of a function as a black box. It takes some inputs and produces some output. The output is the return value. However, printing on screen is not the same as a function output. Why do we use it? You don't "need" to use it, but generally you "want" it. A function can be printing output on screen and do nothing more, which doesn't produce a return value. However, in most cases, you want a function to calculate a value for you, and that value can be used by other operations or functions. Breaking a big problem into smaller pieces of problem, and make functions for the small problems, which can help you to organize and debug your code easily.
24th Dec 2024, 4:15 AM
Wong Hei Ming
Wong Hei Ming - avatar