python - set the return statement of the function to the string

advertisements

Complete newbie to python, only really looked at it this morning. My question is when defining a function how can I set the "return(variable)" statement as a string. I assumed the below would be the correct method however the syntax is incorrect, struggling to find resources online for this particular way of converting the data type. The result is forming as follows:

"The result is:

286"

By converting it to a string it should form: "The result is: 286"

Here is what I thought would work:

def fnc2(a,b,c):
total=(a+b)*c
print("the result is: ") + str(return(total));


A few things:

  1. Python spacing matters, so don't forget to indent!
  2. Check your print syntax. Everything you're printing should be inside the parens

One form of correct syntax would be:

def fnc2(a, b, c):
    total = (a + b) * c
    print("The result is: " + str(total))