Search code examples
pythonreturnreturn-value

Why is the return not returning anything? (closed)


I'm new to Python and learning about the return statement. But when I run this code, it doesn't return anything.

def string_times(str, n):
    return str*n

string_times("Hi", 5)

I've already tried to run this in IDLE and VS Code but it didn't work in either.


Solution

  • The code actually is returning something, but you are not outputting anything to the screen. Simply wrap your function call in a print statement, and it should work:print(string_times("Hi", 5))