Python Forum

Full Version: if and condition not working for string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have three list

out5 = ['increasing', 3, 5,3]

out50 = ['increasing', 9, 5,3]

out95 = ['increasing', 8, 7,3]
I am trying to create this condition

if out5[0]=='increasing' & out50[0] == 'increasing' & out95[0] == 'increasing':
       das = 2
but I get error
Error:
Traceback (most recent call last): File "/Users/mada0007/PycharmProjects/Research_ass/station_data_analysis.py", line 240, in <module> if out5[0] == 'increasing' & out50[0] == 'increasing' & out95[0] == 'increasing': TypeError: unsupported operand type(s) for &: 'str' and 'str'
How can I please overcome this?
To overcome such problems you should learn to read error messages: unsupported operand type(s) for &: 'str' and 'str'

In conditionals you must use 'and' (or 'or') instead of '&'
thanks for reply, that didnt come to mind because I used the same '&' for the same if condition in a different part of my code and it did work.

But thanks though
'&' is 'bitwise AND' but you need 'boolean AND'. You can learn operators and their precedences from official documentation: 6. Expressions >>> 6.16. Operator precedence

If '&' works in your code make sure that it does what you expect it to do.
Thanks!!!!