BaşlayınÜcretsiz Başlayın

Comparisons

Booleans and their truthiness are most often used in comparisions, and we use comparisions without even thinking about their underlying data type. To perform a comparision, we can use a comparision operator. Python supports the following comparision operators:

  • == equal to
  • != not equal to
  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to For this exercise, we'll be using a subset of the Palmer Archipelago (Antarctica) penguin data set, named penguins, as a list of dictionaries with the keys of species, flipper_length, body_mass and sex.

Bu egzersiz

Data Types in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Use a for loop to iterate over the penguins list.
  • Check the penguin entry for a body_mass of more than 3300 grams.
  • Print the species and sex of the penguin if true.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Use a for loop to iterate over the penguins list
for penguin in ____:
  # Check the penguin entry for a body mass of more than 3300 grams
  if penguin["____"] ____ ____:
  	# Print the species and sex of the penguin if true
    print(f"{____} - {____}")
Kodu Düzenle ve Çalıştır