0

What does this does?

imagine I have a function. def h(): print("HI") But what does this mean h( people but a value here) why? like h(hello) h(123) how does it work? i dont get it

7th Jul 2020, 3:30 PM
slawbear
slawbear - avatar
9 Answers
+ 2
Those are arguments that you pass to a function def h(a): print(a) h("hello") here a is parameter ,it can be any name
7th Jul 2020, 3:33 PM
Abhay
Abhay - avatar
+ 1
For Example: def func(arg): print(arg * 3) Here arg is called an argument. An argument is what is passed to a function. Suppose you want a function to add two numbers. Then you would have to give or pass the two numbers the function needs to add them. What temporarily stores the given is called an argument variable. If we call func(arg) to multiply something 3 times here: Func(3): 3 * 3 It will be something like this. The name of argument variable doesn't matter nor does the variable you pass relate to it. Have a good day, Ćheyat
7th Jul 2020, 3:42 PM
Saphal Poudyal
Saphal Poudyal - avatar
0
@Abhay Can you give me a simple example please? It would be very helpful
7th Jul 2020, 3:35 PM
slawbear
slawbear - avatar
0
Here h is just a name given to a function. So that you can execute the codes inside that function by calling its name def h(): print("hi") #calling h h() after h you will see () inside these brackets you can pass arguments to that function. Argument can be of any type like string,int,float,double,boolean etc.. def h(value): print("hello" ,value) val=input("enter name") h(val) Now this code will output hello followed by whatever you typed in the input. You can pass multiple arguments by seperating it with comma def h(value1,value2): print(value1) print(value2) val1="hello" val2="world" h(val1,val2)
7th Jul 2020, 3:38 PM
Shobhith J B
Shobhith J B - avatar
0
@ Shobhith J B why did you first type h(value1,value2) print(value1) print(value2) then call h(val1,val2)??
7th Jul 2020, 3:46 PM
slawbear
slawbear - avatar
0
'''Simply, the value is some data you give the function that it uses ''' #Like def greet(name): print("Whatsup ", name) greet("Samy") '''the function will use Sammy to do something. in this case print it to screen with some other sext ''' def subtract(a, b): print(a - b) subtract(10, 1)
7th Jul 2020, 3:46 PM
Mind To Machine đŸ’»đŸ•†
Mind To Machine đŸ’»đŸ•† - avatar
0
cloroxide What you mean? the names or order of code written?
7th Jul 2020, 3:53 PM
Shobhith J B
Shobhith J B - avatar
0
both @ Shobhith J B
7th Jul 2020, 3:56 PM
slawbear
slawbear - avatar
0
cloroxide About the name it is not neccessary that the name of arguments ie def h(value1,value2): And parameters passed while caling ie h(val1,val2). The name can be any variable name, thay can be different in both..... And about order if you want to call any function it should be already written...so i wrote function first then called that function.
7th Jul 2020, 4:02 PM
Shobhith J B
Shobhith J B - avatar