Boolean ऑपरेटर

इंटरमीडिएट Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Boolean ऑपरेटर

  • and
  • or
  • not
इंटरमीडिएट Python

and

True and True
True
x = 12

x > 5 and x < 15 # True True
True
False and True
False
True and False
False
False and False
False
इंटरमीडिएट Python

or

True or True
True
False or True
True
True or False
True
False or False
False
y = 5

y < 7 or y > 13
True
इंटरमीडिएट Python

not

not True
False
not False
True
इंटरमीडिएट Python

NumPy

bmi     # calculation of bmi left out
array([21.852, 20.975, 21.75 , 24.747, 21.441])
bmi > 21
array([True, False, True, True, True], dtype=bool)
bmi < 22
array([True, True, True, False, True], dtype=bool)
bmi > 21 and bmi < 22
ValueError: The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()
इंटरमीडिएट Python

NumPy

  • logical_and()
  • logical_or()
  • logical_not()
np.logical_and(bmi > 21, bmi < 22)
array([True, False, True, False, True], dtype=bool)
bmi[np.logical_and(bmi > 21, bmi < 22)]
array([21.852, 21.75, 21.441])
इंटरमीडिएट Python

अभ्यास करते हैं!

इंटरमीडिएट Python

Preparing Video For Download...