+ 1
in some programs calling the function is like just function(x+y) in some programs we are using print(funtction(x+y)) what is the difference
5 Respostas
+ 2
alright.. for example you have a function called test() and it returns True at the end..
and you want to see if it works so you wanna make sure that it actuallly returns True. In order to do that you simply call that function inside print(test()) and you will be able to see on the console the value that it returns
otherwise if you call just by test() it will not be seen by human eye. Only the computer will be able to see that value.
+ 1
print is a function present in python, which return on the screen a string, a value or a result from another function. if you just call a function that does not return anything on the screen you are not able to see the result. sometime you do not need to, so you avoid to have it printed
0
print: gives the value to the user as an output string.print(3) would give a string'3' to the screen for the user to view. The program would lose the value.
return: gives the value to the program. Callers of the function then have the actual data and data type (bool, int, etc...) return 3 would have the value 3 put in place of where the function was called.
0
I still dint understand
0
The two cases are:
1) val= function(x+y)
In this case any value returend by function is assigned to variable "val" and it can be used any where in rest of the code.
Eg: print(val)
2) print(function(x+y)
In this case the return value from function is not stored in any variable but directly passed to function print() as input.