0
What is the use of User-made functions? wouldn't it be easier to define a var? Or do I have functions mixed up?
7 Antworten
+ 3
here is an example with a function:
def calc(val1, val2, op):
print('operator is ',type(op))
if op == '+':
return val1 + val2
if op == '-':
return val1 - val2
res = calc(3, 5, '+')
print(res)
The function 'calc()' can take 3 arguments: val1 and val2 - both should be numeric values. The last var is op which gets a string variable like '+'. so a function can get arguments as int, float, string, list ...
the function can store these recived objects and can use them for processing. when function will be terminated the variables are deleted. same happens to variables of the main programm.
if you mean 'store' in terms of using values for a future use they has to be stored in file and can then be read and used again.
0
Your question is unclear
0
can you explain a function?
0
A function is a piece of code which you can reuse over and over, a variable stores a value.
0
so the value can be a string?
0
Of a variable yes, not of a function.
0
so a function can't store a string?