Bool Object is not Subscriptable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Bool Object is not Subscriptable (/thread-33526.html) |
Bool Object is not Subscriptable - quest - May-02-2021 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.stateHowever if my state is False, I cannot compare 'Bell' and False and I have this error: 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? RE: Bool Object is not Subscriptable - Yoriz - May-02-2021 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=Falseif state is False then set state to False
|