+ 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

2nd Dec 2016, 4:03 AM
Aditya Shashanka
Aditya Shashanka - avatar
5 Respuestas
+ 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.
2nd Dec 2016, 4:21 AM
Nedim Kanat
Nedim Kanat - avatar
+ 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
24th Dec 2016, 8:25 PM
Claudio Nespoli
Claudio Nespoli - avatar
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.
2nd Dec 2016, 4:13 AM
Nedim Kanat
Nedim Kanat - avatar
0
I still dint understand
2nd Dec 2016, 4:18 AM
Aditya Shashanka
Aditya Shashanka - avatar
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.
2nd Dec 2016, 6:23 AM
Manch
Manch - avatar