What is function and its parameters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is function and its parameters

20th Nov 2017, 1:11 AM
Rahul
Rahul - avatar
8 Answers
+ 7
That helps me alot too. Thank you Malkon !
20th Nov 2017, 2:34 AM
Danay
Danay - avatar
+ 5
Parameters are still a little confusing for me too, but functions seem to be what you are telling the code to do when you run it.
20th Nov 2017, 1:15 AM
Danay
Danay - avatar
+ 5
Ok I think parameters are where you name, and choose a variable you are going to use in the argument. Somebody with some knowledge please let me know if that's close lol
20th Nov 2017, 1:29 AM
Danay
Danay - avatar
+ 5
parameter is the variable that will receive a value in a method or function. myMethod( String par){ print "The parameter my method received was $par"; }
20th Nov 2017, 2:33 AM
Malkon F
Malkon F - avatar
+ 4
in Java we have the methods, which in general, basically is the same thing as function. Their function is to do some task and may or may not return some value. myMethod{ print "hello"; } the work of this method is to display hello on your screen.
20th Nov 2017, 2:27 AM
Malkon F
Malkon F - avatar
+ 4
in the method definition step, if you can not define the method with one word then it is not a good method. You will have to try to divide in two methods. Well constructed methods do something very specific and do well. #not so good way singARockSong{ . . } singASambaSong{ . . } #best way sing(Music rock){ play rock; } sing(Music samba){ play samba; }
20th Nov 2017, 2:39 AM
Malkon F
Malkon F - avatar
+ 3
The parameters are the placeholders for the arguments. When you call the function with some arguments (values), the function takes the arguments and assign them to the parameters (variables). Then the function uses the parameters to do some work. Python Example 1: def get_sum(a, b): # Param. a and b return a + b sum = get_sum(5, 10) # Args. 5 and 10 print(sum) # 15 Python Example 2: def max_number(n1, n2): if (n1 > n2): return n1 return n2 a = 12 b = 4 max = max_number(a, b) print(max) # 12
20th Nov 2017, 2:46 AM
Boris Batinkov
Boris Batinkov - avatar