Vergleichsoperatoren

Python für Fortgeschrittene

Hugo Bowne-Anderson

Data Scientist at DataCamp

NumPy-Gedächtnisstütze

# Code from Intro to Python for Data Science, Chapter 4
import numpy as np
np_height = np.array([1.73, 1.68, 1.71, 1.89, 1.79])
np_weight = np.array([65.4, 59.2, 63.6, 88.4, 68.7])
bmi = np_weight / np_height ** 2
bmi
array([ 21.852,  20.975,  21.75 ,  24.747,  21.441])
bmi > 23
array([False, False, False,  True, False], dtype=bool)
bmi[bmi > 23]
array([ 24.747])
  • Vergleichsoperatoren: Wie Python-Werte zusammenhängen
Python für Fortgeschrittene

Numerische Vergleiche

2 < 3
True
2 == 3
False
2 <= 3
True
3 <= 3
True
x = 2
y = 3

x < y
True
Python für Fortgeschrittene

Weitere Vergleiche

"carl" < "chris"
True
3 < "chris"
TypeError: unorderable types: int() < str()
3 < 4.1
True
Python für Fortgeschrittene

Weitere Vergleiche

bmi
array([21.852, 20.975, 21.75 , 24.747, 21.441])
bmi > 23
array([False, False, False, True, False], dtype=bool)
Python für Fortgeschrittene

Vergleichsoperatoren

Operator Bedeutung
< Kleiner als
<= Kleiner oder gleich
> Größer als
>= Größer als oder gleich
== Gleich
!= Nicht gleich
Python für Fortgeschrittene

Lass uns üben!

Python für Fortgeschrittene

Preparing Video For Download...