Given the example
if row[3] == ' male' & row[5] == 0 & row[6] == 0;
i want to check more than one variable , it keeps on giving me an error can someone politely right an example code of how to accomplish this
Given the example
if row[3] == ' male' & row[5] == 0 & row[6] == 0;
i want to check more than one variable , it keeps on giving me an error can someone politely right an example code of how to accomplish this
By using the and
keyword or &
character as you have done:-
if row[3] == 'male' and row[5] == 0 and row[6] == 0:
if row[3] == 'male' & row[5] == 0 & row[6] == 0:
However, you've used a semi-colon (;
) at the end of your if
statement, when it should have been a colon (:
) which tells your Python interpreter to expect indented code. A semi colon terminates a statement, only really used in Python when you want to put two statements on one line. In this case it will not execute the intended if
"block"
For future reference:
If you are asking questions on StackOverflow about an error, post the error in case you have misunderstood its intention like in this case.
while the other answer is better, you can also use &
(bitwise and operator):
if (row[3] == ' male') & (row[5] == 0) & (row[6] == 0):
To use multiple conditions use the and
keyword
if (row[3] == ' male' and row[5] == 0 and row[6] == 0):
The ()
make it easier to read. Also you need to use :
instead of ;
.