+ 2
What is function and its parameters
8 Answers
+ 7
That helps me alot too. Thank you Malkon !
+ 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.
+ 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
+ 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";
}
+ 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.
+ 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;
}
+ 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
+ 3
https://www.sololearn.com/Discuss/829541/?ref=app
https://www.sololearn.com/Discuss/680872/?ref=app
https://www.sololearn.com/Discuss/712868/?ref=app
https://www.sololearn.com/Discuss/733526/?ref=app
https://www.sololearn.com/Discuss/788445/?ref=app
https://www.sololearn.com/Discuss/573838/?ref=app
https://www.sololearn.com/Discuss/401100/?ref=app
https://www.sololearn.com/Discuss/760668/?ref=app
https://www.sololearn.com/Discuss/689046/?ref=app
https://www.sololearn.com/Discuss/572327/?ref=app
https://www.sololearn.com/Discuss/460693/?ref=app
https://www.sololearn.com/Discuss/571125/?ref=app