print(a_method)
is telling Python to print what print_method
is, which is a function. However, you want it to print what the function returns when called, so you should have used print(a_method())
, since calling the function looks like a_method()
.
However, your code appears confused in a few more ways, so that's not even really the problem. Here's what I think you tried to do:
def with_price(price: float, factor: float = 2.0):
return (price * factor)
def a_method(a: float, price_func):
b = price_func(11)
return a * b
print(a_method(5, with_price))
This calls a_method
, with a
set to 5
and price_func
set to with_price
. So, it computes b
as 11 * 2.0
, which is 22
and then returns 5 * 22
, which is 110
.
Note that doing it like this will cause factor
to always be 2.0
since you provide no way of passing another value.
Also, you named things 'methods', but they are really just functions. Methods are functions defined on an object, which expect the first parameter to be a reference to the object they are being called on. You could turn them into methods by adding something like self
as the first parameter and including them in the body of a class.