I was trying a simple piece of code, get someone's name and age and let him/her know when they turn 21... not considering negatives and all that, just random.
I keep getting this 'int' object is not subscriptable
error.
name1 = raw_input("What's your name? ") age1 = raw_input ("how old are you? ") x = 0 int([x[age1]]) twentyone = 21 - x print "Hi, " + name1+ " you will be 21 in: " + twentyone + " years."
The TypeError: 'int' object is not subscriptable error occurs if we try to index or slice the integer as if it is a subscriptable object like list, dict, or string objects. The issue can be resolved by removing any indexing or slicing to access the values of the integer object.
The “typeerror: 'int' object is not subscriptable” error is raised when you try to access an integer as if it were a subscriptable object, like a list or a dictionary. To solve this problem, make sure that you do not use slicing or indexing to access values in an integer.
Methods are not subscriptable objects and therefore cannot be accessed like a list with square brackets. To solve this error, replace the square brackets with the round brackets after the method's name when you are calling it.
How to Fix Int Object is Not Iterable. One way to fix it is to pass the variable into the range() function. In Python, the range function checks the variable passed into it and returns a series of numbers starting from 0 and stopping right before the specified number.
When you type x = 0
that is creating a new int
variable (name) and assigning a zero to it.
When you type x[age1]
that is trying to access the age1
'th entry, as if x
were an array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With