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

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 
    else:
       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:

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?
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 679 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  Help with python 'not subscriptable' error Extra 3 1,976 Dec-16-2022, 05:55 PM
Last Post: woooee
  TypeError: 'NoneType' object is not subscriptable syafiq14 3 5,164 Sep-19-2022, 02:43 PM
Last Post: Larz60+
  'int' object is not subscriptable after API call ed8484 1 1,765 Sep-18-2021, 02:06 PM
Last Post: ed8484
  Message='int' object is not subscriptable DanielCook 4 2,262 Aug-10-2021, 05:21 PM
Last Post: deanhystad
  Float Object is not Subscriptable quest 2 2,853 Apr-20-2021, 09:28 AM
Last Post: quest
  TypeError: 'NoneType' object is not subscriptable Jmekubo 6 27,222 Sep-08-2020, 10:03 AM
Last Post: DigiTMG
  TypeError: 'type' object is not subscriptable Stef 1 4,440 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 3,187 Aug-25-2020, 03:50 PM
Last Post: Rejoice
  'NoneType' object is not subscriptable Justchse 4 3,659 Aug-01-2020, 06:18 PM
Last Post: Justchse

Forum Jump:

User Panel Messages

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