Solved – typeerror: ‘int’ object is not subscriptable
Posted on: March 12, 2021 by Deven
In this article, you will learn how to solve typeerror: ‘int’ object is not subscriptable error in Python.
Let’s look at a code example that produces the same error.
Dateofbirth = int(input("When is your birthday? (dddd) "))
day = Dateofbirth[0:2]
print("Day:", day)
Output
When is your birthday? ((dddd) 20
Traceback (most recent call last):
File "<string>", line 3, in <module>
TypeError: 'int' object is not subscriptable
In order to solve typeerror: ‘int’ object is not subscriptable error you have to remove the int()
statement from the code snippet above.
Consider the example below:
Dateofbirth = input("When is your birthday? (dddd) ")
day = Dateofbirth[0:2]
print("Day:", day)
Output
When is your birthday? (dddd) 20
Day: 20
Share on social media
//