In [1]:
a = 1
result = 'even' if a % 2 == 0 else 'odd'
print(result)
In [2]:
a = 2
result = 'even' if a % 2 == 0 else 'odd'
print(result)
In [3]:
a = 1
result = a * 2 if a % 2 == 0 else a * 3
print(result)
In [4]:
a = 2
result = a * 2 if a % 2 == 0 else a * 3
print(result)
In [5]:
a = 1
print('even') if a % 2 == 0 else print('odd')
In [6]:
a = 1
if a % 2 == 0:
print('even')
else:
print('odd')
In [7]:
a = -2
result = 'negative and even' if a < 0 and a % 2 == 0 else 'positive or odd'
print(result)
In [8]:
a = -1
result = 'negative and even' if a < 0 and a % 2 == 0 else 'positive or odd'
print(result)
In [9]:
a = 2
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
In [10]:
a = -2
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
In [11]:
a = 0
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
In [12]:
l = ['even' if i % 2 == 0 else i for i in range(10)]
print(l)
In [13]:
l = [i * 10 if i % 2 == 0 else i for i in range(10)]
print(l)
In [14]:
get_odd_even = lambda x: 'even' if x % 2 == 0 else 'odd'
In [15]:
print(get_odd_even(1))
In [16]:
print(get_odd_even(2))