close

[Solved] Type: ‘function’ object is not subscriptable – Python

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Type: ‘function’ 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 Type: ‘function’ object is not subscriptable – Python Error Occurs?

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

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

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

    To Solve Type: 'function' object is not subscriptable – Python Error You have two objects both named bank_holiday — one a list and one a function. Disambiguate the two.

  2. Type: 'function' object is not subscriptable – Python

    To Solve Type: 'function' object is not subscriptable – Python Error You have two objects both named bank_holiday — one a list and one a function. Disambiguate the two.

Solution 1

You have two objects both named bank_holiday — one a list and one a function. Disambiguate the two.

bank_holiday[month] is raising an error because Python thinks bank_holiday refers to the function (the last object bound to the name bank_holiday), whereas you probably intend it to mean the list.

Solution 2

It is so simple, you have 2 objects with the same name, and when you say: bank_holiday[month] Python thinks you wanna run your function and got ERROR.

Just rename your array to bank_holidays <— add a ‘s‘ at the end! like this:

bank_holidays= [1, 0, 1, 1, 2, 0, 0, 1, 0, 0, 0, 2] #gives the list of bank holidays in each month

def bank_holiday(month):
   if month <1 or month > 12:
       print("Error: Out of range")
       return
   print(bank_holidays[month-1],"holiday(s) in this month 😍")

bank_holiday(int(input("Which month would you like to check out: ")))

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