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 डेटा सेट के एक subsetpenguinsका उपयोग करेंगे, जो डिक्शनरियों की एक list है जिसमेंspecies,flipper_length,body_massऔरsexकीज़ हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में डेटा टाइप्स
अभ्यास निर्देश
penguinsलिस्ट पर iterate करने के लिए एक for loop का उपयोग करें.- ऐसी penguin एंट्री जाँचें जिसका
body_mass3300 ग्राम से अधिक हो. - अगर शर्त सही हो, तो उस 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"{____} - {____}")