Does return do the same function as print does?

Does return do the same function as print does?

5 Likes

No, having two keywords which do the same thing wouldn’t be very practical.

return does what it says, handing something back:

def example():
   return "hello world"

# store returned result in variable
x = example()

# now lets print the returned result
# which we captured in x
print x
11 Likes

I don’t get it what does “return does what it says” mean

1 Like

In the literal sense, what does return mean? It could be returning a book to the library or returning something you borrowed from your neighbor.

same with your function, it hands back data.

1 Like

In your example, if we dont define x = example() and do print example (), will that work?

depends on your definition of work, if the purpose is purely to print(), then yes

However, by storing the returned value in a variable, we can use it later.

2 Likes

excuse me Can you see this?

def cube(number): 

return number * number * number

def by_three(number):

 if number % 3 == 0:

  return cube(number) 

  else:

    return False

Can you fix this bug? it needs to fix everything. also I need to go on the other section if you please fix this problem

Please read this topic:

[How-to] Create a topic that everyone will read

I formatted the code for you, but indention on this line:

return number * number * number

still does not look right.

Also, what error do you get? And can you provide the exercise url/link?

1 Like

a bug. however i used “replace solution” to make it work