What does function mean ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does function mean ?

Function

16th Jun 2019, 6:06 PM
The unknown 321
The unknown 321 - avatar
9 Answers
+ 6
Function: Function is an operation, which takes in values and processes them to return new values. Function in programming: In programming, functions are defined, named block of code, that will be executed when called. Function is called, when you execute function_name(); Example (Python): >>>def sum(x, y): ... return x + y ... >>>print(sum(5, 7)) 12 >>>#12 was printed, because 5 was passed in sum as x "x = 5", and 7 was passed in sum as y "y = 7", and sum returned x + y "return 5 + 7" => "return 12". >>>#It returned 12 where sum was called (in print statement) then print was called with 12 as argument, then print printed 12
16th Jun 2019, 7:00 PM
Seb TheS
Seb TheS - avatar
+ 2
Yes, functions are a great way to do things. You can make many as you need. The term "function" is from math, basically is the same thing. I don't know Python enough but some other languages have a "Main Function" and that's the function the program execute in order to run. You can create many functions to accomplish what you want but in order to use those you need to call them inside the "Main function". Almost every language works at similar manner but to be more precise, what language do you use?
16th Jun 2019, 9:28 PM
Jonas
Jonas - avatar
+ 2
C++
16th Jun 2019, 9:29 PM
The unknown 321
The unknown 321 - avatar
16th Jun 2019, 9:55 PM
Seb TheS
Seb TheS - avatar
+ 1
Thanks. So if I'm not wrong function means the main thing right ?
16th Jun 2019, 6:36 PM
The unknown 321
The unknown 321 - avatar
+ 1
Can you please give some examples
16th Jun 2019, 9:30 PM
The unknown 321
The unknown 321 - avatar
+ 1
Sure.. Look at this code: If you comment or erase the method "SayHi();" inside Main method, the program will do nothing. That's because the program only execute things inside the Main. https://code.sololearn.com/cmD3uYH3620d/?ref=app
16th Jun 2019, 9:40 PM
Jonas
Jonas - avatar
+ 1
If you want more info you can watch the video in this link. It is a great YouTube channel for beginners in almost every mayor language. https://www.youtube.com/playlist?list=PLLAZ4kZ9dFpOSzRXG05goZMgsvXwDDL6g
16th Jun 2019, 9:41 PM
Jonas
Jonas - avatar
+ 1
Seb TheS The code is good for some advance fellow programmers. It is better try to not show off but make it simpler in order to explain something (it is a good code though). At least you can comment it to explain your answer... Baby steps, ma' friend.
16th Jun 2019, 10:04 PM
Jonas
Jonas - avatar