Skip to content
Advertisement

How do I create this function correctly?

I have defined a function string_adder that receives two arguments and returns a concatenated version of both arguments.

def string_adder(a,b):
    bac = a + " " + b
    return bac

string_adder("boy","girl")
print (string_adder)

However, when I run the code, I get this error message:

<function string_adder at 0x10cf5bb90>

Any advice on what I’m doing wrong?

Advertisement

Answer

On the line string_adder("boy","girl") you call the function but don’t do anything with what it returns. You need to change it to string_adder = string_adder("boy","girl"), probably with a different variable name for ease of reading. You’d need to change the print line in that case too.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement