This question already has answers here:
int object not callable error in python [closed]
(2 answers)
Closed 2 years ago.
I have researched this error and know that it has something to do with the naming of my variables, but I don't see any variables in my code that are "magic words". What am I missing? Thanks!
def shrink_inv (p,r,n,t):
return p(1+r/n)**n*t
shrink_inv(10,-0.1,1,1)
return p(1+r/n)**n*t
You are missing an operator after p - it's currently interpreted as a function call.
Related
This question already has answers here:
How to check for a function type in Python?
(4 answers)
Closed 2 years ago.
How can I check whether a function is a function type in python?
I did this:
print(type(func_1))
python tells me that this is a
<class 'function'>
However, when I did this:
print(type(func_1) is function)
I got a NameError
NameError: name 'function' is not defined
you could compare it to the type of a lambda function (same thing)
print(type(func_1) == type(lambda:None))
This question already has answers here:
Why isn't the 'len' function inherited by dictionaries and lists in Python
(7 answers)
Why does Python code use len() function instead of a length method?
(7 answers)
In Python, when should I use a function instead of a method?
(5 answers)
Difference between len() and .__len__()?
(5 answers)
Closed 4 years ago.
In Python, why are some built-in functions called using brackets with the method name before the object, e.g.
print("foobar")
bool("foobar")
...
While others are built-in method attributes, called with a dot behind the object, e.g.
"foobar".capitalize()
Specifically I'm interested to learn if there is a general principle behind this instead of just common practice and memorization. In cases where you can't quite remember whether it was capitalize("foobar") or "foobar".capitalize(), how do you know?
This question already has answers here:
What does it mean to "call" a function in Python? [closed]
(4 answers)
Closed 5 years ago.
I am new to programming, and trying out with a little Python3.
I have some trouble understanding the concept behind calling a function? having the defined the following function, what would be the proper way to call it?
def string_length(mystring):
return len(mystring)
Thanks in advance guys
def string_length(mystring):
return len(mystring)
print(string_length('something'))
Like that
length = string_length('some_string')
where length is a variable that will store the output.
This question already has answers here:
Bare asterisk in function parameters?
(6 answers)
What is the purpose of class methods?
(18 answers)
Closed 5 years ago.
Looking into the Python documentation, I came across the following page:
https://docs.python.org/3/library/stdtypes.html#int.from_bytes
Here, the third argument of int.from_bytes() is *. What does * represent and why can it be ignored in the examples?
Also, the fromkeys(seq[, value]) method is said to be a classmethod, but what exactly does this mean? What class does this method belong to?
This question already has answers here:
Accessing attributes on literals work on all types, but not `int`; why? [duplicate]
(4 answers)
Closed 6 years ago.
I just want to understand the behavior of method call on integer object.
I can't call __add__ method directly on integer.
5.__add__(5)
This gives me: SyntaxError: invalid syntax
However, doing num = 5 and call num.__add__(5) works fine.
How assigning name to an integer object makes difference?
it is just syntax. The Parser reads:
"5." -> a float :)
"__add__" -> why that? I don't understand :(