+ 3

What is the difference between a function and a variable?

5th Feb 2017, 5:04 PM
Roy blanchard
7 Answers
+ 7
Function- def add(x,z): a=x b=z c=a+b return c called with. add(2,3) variable- name="justin" called with. name A variable is basically a box. it holds a value. a function is a bit of code that does something. it can be anything from add numbers. change x and y coordinates. any action you need performed and want to make easily repeatable. For instance, above I wanted to add 2 numbers. instead of writing 2 variables and then adding them together to get another variable.. and repeating that process each time I want to add a different set of numbers. instead I can write that function 1 time. then if I want to add a few sets of numbers it's repeatable.. add(2,3) .. add(5,7) .. add(12,2) .. etc a variable can be called to give a value, such as a name, in many places without needing to change each place. Anyplace you use name it will result in whatever value you stored in the name variable. If you change the variable, it will change anywhere you called it
5th Feb 2017, 5:45 PM
LordHill
LordHill - avatar
+ 5
variable is unit of information. function is action or set of actions performed on variables.
5th Feb 2017, 5:11 PM
Aidas K
Aidas K - avatar
+ 2
A variable is like a place to store something in. for example egg = 5 egg is a variable that int 5 is stored in it so if in sell you print egg you will recieve number 5. variable could name anything you want. A function is like a factory that pack a special product. we use function to have an especial product. coz we can call functions later so it is really helful that we do not need to type all the code again. instead we call the function. imagine we have a function that produce a factorial by given numbers. so every time you need factorial, you just need to call your function by the numbers you want. It makes everything easier.
1st Dec 2017, 12:24 PM
Shabnam
Shabnam - avatar
+ 1
function is a collection of some instruction that done a specific task and whose value vary during the program execution is called variable
5th Feb 2017, 5:13 PM
Jonty Bamrah
+ 1
Technically, functions are objects, too, which can also be assigned to variables, so the difference is not "variables hold information, functions do things", but rather "variables are pointers to data, which objects hold, and function is a type of object". They are different at core level.
5th Feb 2017, 5:55 PM
DotJason
0
Variables are using in functions as x,y,... Variables are Like constants but you determine itsvalue of its. Functions are prepared code(with variable,constants,loops ,sub function ,list,...)
5th Feb 2017, 7:59 PM
morteza rakhshani nejad
morteza rakhshani nejad - avatar
0
A function is a set of code which does something you want to do it for this it requires some input to work on, these inputs are stored in variables. if the variables are defined under the body of functions then only function can access it otherwise if they are defined globally any function can access it
7th Feb 2017, 6:43 AM
Ashish Wayne
Ashish Wayne - avatar