close

[Solved] Error: ‘int’ object is not subscriptable – Python

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Error: ‘int’ object is not subscriptable – Python in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Error: ‘int’ object is not subscriptable – Python Error Occurs?

Today I get the following error Error: ‘int’ object is not subscriptable – Python in python.

How To Solve Error: ‘int’ object is not subscriptable – Python Error ?

  1. How To Solve Error: 'int' object is not subscriptable – Python Error ?

    To Solve Error: 'int' object is not subscriptable – Python Error When you type x = 0 that is creating a new int variable (name) and assigning a zero to it.

  2. Error: 'int' object is not subscriptable – Python

    To Solve Error: 'int' object is not subscriptable – Python Error When you type x = 0 that is creating a new int variable (name) and assigning a zero to it.

Solution 1

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.

Solution 2

The problem is in the line,

int([x[age1]])

What you want is

x = int(age1)

You also need to convert the int to a string for the output…

print "Hi, " + name1+ " you will be 21 in: " + str(twentyone) + " years."

The complete script looks like,

name1 = raw_input("What's your name? ")
age1 = raw_input ("how old are you? ")
x = 0
x = int(age1)
twentyone = 21 - x
print "Hi, " + name1+ " you will be 21 in: " + str(twentyone) + " years."

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read