शुरू करेंमुफ़्त में शुरू करें

Comparisons

Booleans और उनकी truthiness का इस्तेमाल अक्सर comparisons में होता है, और हम comparisons करते समय उनके underlying data type के बारे में सोचे बिना ही काम कर लेते हैं. किसी comparison को करने के लिए हम comparison operator का उपयोग करते हैं. Python निम्नलिखित comparison operators सपोर्ट करता है:

  • == equal to
  • != not equal to
  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to इस अभ्यास में हम Palmer Archipelago (Antarctica) के penguin डेटा सेट के एक subset penguins का उपयोग करेंगे, जो डिक्शनरियों की एक list है जिसमें species, flipper_length, body_mass और sex कीज़ हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में डेटा टाइप्स

पाठ्यक्रम देखें

अभ्यास निर्देश

  • penguins लिस्ट पर iterate करने के लिए एक for loop का उपयोग करें.
  • ऐसी penguin एंट्री जाँचें जिसका body_mass 3300 ग्राम से अधिक हो.
  • अगर शर्त सही हो, तो उस penguin के species और sex को प्रिंट करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# 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"{____} - {____}")
कोड संपादित करें और चलाएँ