Python Forum

Full Version: Bool Object is not Subscriptable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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