+ 3

What is the difference of Return and Print?

What is the purpose of return? Wouldn't print just be easier?

28th Sep 2018, 7:00 PM
DrChicken24
DrChicken24 - avatar
2 Respostas
+ 3
return gets you variables from the local namespace of functions so you can use them in your global namespace. # local function namespace def add(a, b): res = a + b return res #global namespace a = 1 b = 2 sum = add(a, b) print(sum) output: 3 print() prints the objects you provided, for instance a string and/or variables, to your screen. def foo(bar): print("Hello") print("World) output: "Hello" "World"
28th Sep 2018, 7:12 PM
Kevin Dietrichstein
Kevin Dietrichstein - avatar
+ 1
Kevin Dietrichstein So return is like print for functions?
28th Sep 2018, 11:53 PM
DrChicken24
DrChicken24 - avatar