Answers for "python if statement multiple lines"

8

python if statement multiple lines

# ex. 1
if (cond1 == 'val1' and cond2 == 'val2' and 
       cond3 == 'val3' and cond4 == 'val4'):
    do_something
    
# Also, don't forget the whitespace is more flexible than you might think:
# ex. 2
if (   
       cond1 == 'val1' and cond2 == 'val2' and 
       cond3 == 'val3' and cond4 == 'val4'
   ):
    do_something
if    (cond1 == 'val1' and cond2 == 'val2' and 
       cond3 == 'val3' and cond4 == 'val4'):
    do_something
Posted by: Guest on June-12-2020
5

python double condition if

if conditionA and conditionB:
	print('and')
    
if conditionA or conditionB:
  	print('or')
Posted by: Guest on May-21-2020
0

multiple if else in python in one line

a = "neg" if b<0 else "pos" if b>0 else "zero"
Posted by: Guest on August-23-2021
0

multiple if else condition in single line in python

>>> i=100
>>> a = 1 if i<100 else 2 if i>100 else 0
>>> a
0
>>> i=101
>>> a = 1 if i<100 else 2 if i>100 else 0
>>> a
2
>>> i=99
>>> a = 1 if i<100 else 2 if i>100 else 0
>>> a
1
Posted by: Guest on May-05-2021

Code answers related to "python if statement multiple lines"

Python Answers by Framework

Browse Popular Code Answers by Language