简体   繁体   中英

I don't understand this error <function get_multiples_of_3 at 0x10a341510> or what this means?

I'm meant to write a function in python that returns a list of multiples of 3 this is the code I wrote:

def get_multiples_of_3(numbers):
    list_num = []

    if numbers:
        for n in numbers:
            if(n%3 == 0):
                list_num.append(n)
        return list_num
    else:
        return numbers

print(get_multiples_of_3)

but my return gave: <function get_multiples_of_3 at 0x7f00ccd761f0> [3, 6, 9, 15, 30]

I don't understand why the <> part is returned but also my expected values are returned too. the program I put my function into has an inbuilt list

print(get_multiples_of_3([1, 2, 3]))

You have to pass something to the function. And it should be an iterable object, such as a list.

numbers = [1, 2, 3]
def get_multiples_of_3():
    list_num = []

    if numbers:
        for n in numbers:
            if(n%3 == 0):
                list_num.append(n)
        return list_num
    else:
        return numbers


print(get_multiples_of_3())

If the data 'numbers' available for the function. Place them higher. And call the function without arguments. And don't call the function without parentheses(). Without parentheses, you will get the function object itself.

You are not calling the function, you are merely printing its definition.

You need to call the function like so:

print(get_multiples_of_3([1, 2, 3]))

your are giving back the function as object and not the function with parameters as it is defined, that's why you are receiving the internal representation of the object( repl ) and not expected return value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM