Python Forum
Bool Object is not Subscriptable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bool Object is not Subscriptable

I want to compare string and bool.
Here is my function:
def MyFunction(qbt, Pauli):
    if qbt.QEO.state[0]=='Bell':

    elif qbt.QEO.state==False: qbt.QEO.state=False 
       raise NotImplementedError("Unknown State")  
    return  qbt.QEO.state    
However if my state is False, I cannot compare 'Bell' and False and I have this error:

Bool Object is not Subscriptable
It is probably because of this line:
if qbt.QEO.state[0]=='Bell'
If my state is False, then I cannot compare False and 'Bell'. How to solve this error?
What are the possible value types of state, in the above sample state is a bool, not a list so you cannot index it.
You might need to find out what type of value you're dealing with first.

This line is redundant
elif qbt.QEO.state==False: qbt.QEO.state=False 
if state is False then set state to False

Possibly Related Threads…
Thread Author Replies Views Last Post
  'int' object is not subscriptable after API call ed8484 1 145 Sep-18-2021, 02:06 PM
Last Post: ed8484
  TypeError: 'NoneType' object is not subscriptable syafiq14 2 1,396 Aug-26-2021, 06:18 AM
Last Post: alexaminar
  Message='int' object is not subscriptable DanielCook 4 337 Aug-10-2021, 05:21 PM
Last Post: deanhystad
  Float Object is not Subscriptable quest 2 768 Apr-20-2021, 09:28 AM
Last Post: quest
  TypeError: 'NoneType' object is not subscriptable Jmekubo 6 23,922 Sep-08-2020, 10:03 AM
Last Post: DigiTMG
  TypeError: 'type' object is not subscriptable Stef 1 1,517 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item() Rejoice 6 1,360 Aug-25-2020, 03:50 PM
Last Post: Rejoice
  'NoneType' object is not subscriptable Justchse 4 1,470 Aug-01-2020, 06:18 PM
Last Post: Justchse
  bool b = (num == 100) this doesn't work? MelonMusk 2 884 Jun-12-2020, 02:18 AM
Last Post: bowlofred
  'AxesSubplot' object is not subscriptable amitsinbox 0 4,570 Apr-30-2020, 07:57 AM
Last Post: amitsinbox

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020