Function object is not subscriptable in Python? - python

So I try to pass this through Python:
print("Strength:",stats[0])
print("Defense:",stats[1])
print("Agility:",stats[2])
...and I get this in return:
TypeError: 'function' object is not subscriptable
What does this mean and how do I fix it?

It means that stats is a function instead of a sequence. Perhaps you forgot the parens on an earlier function call.

Related

Taking "'int' object is not callable " (Done)

hope you are all in safe. I just wanted to get (20^5)-(1^5)/5(20-1)
myNum = ((20**5)-(1**5))/5(20-1)
print(myNum)
I took the TypeError: 'int' object is not callable
Then I changed it like;
print(((20**5)-(1**5))/5(20-1))
But I'm still getting same error. I checked the solutions but didn't understand what am I have to do.
Fix: ((20**5)-(1**5))/5/(20-1)
Error is that you can't omit multiply sign here: 5(20-1).
Interpreter considers you're trying to call function like f(...), but 5 is not a function, that's why you see error:
TypeError: 'int' object is not callable
^^^ ^^^^^^^^
5 (20-1)

what is wrong with my code ? i wanted to see the transformations i did instead getting the error meassage

I am getting attribute error:
AttributeError: 'function' object has no attribute 'suffix'
credit_risk_transform=credit_risk[num_list].copy()
squared=(credit_risk_transform**2).add.suffix("squared")
square_root=(credit_risk_transform**0.5).add.suffix("_sqrt")
natural_log=np.log(credit_risk_transform+1).add,suffix("_ln")
credit_risk_transform=pd.concat([credit_risk_transform,squared,square_root,natural_log],axis=1)
credit_risk_transform.drop(['default_squared','default__sqrt','default_ln'],axis=1,inplace=True)
credit_risk_transform.head()
I wanted to see the transformations I did instead getting the error message
this is the function you are using wrong
add_suffix("squared")
add.suffix() means you are calling the suffix function of add attribute. Use add_suffix("squared") instead.

'NoneType' object is not callable for an object that has a value?

I have the following two lines of code:
print(test)
print(test.type())
There is something being printed out by the code, namely the value of test. However, when I check the type of test through test.type(), i get the error TypeError: 'NoneType' object is not callable. How is this possible?
test.type is None.
Use type(test) instead.

Difficulty in understanding the error in python

I wrote a piece of code in python that reads a string, split it into 2 parts,the first being a string again and the second being an integer.
For example
ABDKEK 1255443
The code is as follows:
L=raw_input()
ls=L.split()
num=int(ls[1])
L=ls[0]
len=len(L)
and it gives the following error
len=len(L)
TypeError: 'int' object is not callable
I make the following change in the code:
length=len(L)
and it works.
Can anyone explain what does the error 'int' object is not callable mean??
len is a function name which is already defined and should not be use as a variable. Try some other name instead.

Append result of variable to a list

I am trying to add the result of a variable f to the end of a list list_name. However, when I try to do this I get the following error:
list_name.append[f]
TypeError: 'builtin_function_or_method' object is not subscriptable
What am I doing wrong?
list_name.append(f)
append is a method (function) so you should call it with simple parentheses.
And of course, a function is not subscriptable, so you get an error...
(An object is subscriptable when it has a __getitem__ method.)

Categories

Resources