तुलना ऑपरेटर

इंटरमीडिएट Python फॉर फाइनेंस

Kennedy Behrman

Data Engineer, Author, Founder

Python के तुलना ऑपरेटर

  • समानता: ==,!=
  • क्रम: <,>,<=,>=
इंटरमीडिएट Python फॉर फाइनेंस

Equality ऑपरेटर बनाम असाइनमेंट

समानता जाँचें: ==

मान असाइन करें: =

इंटरमीडिएट Python फॉर फाइनेंस

Equality ऑपरेटर बनाम असाइनमेंट

13 == 13
True
count = 13
print(count)
13
इंटरमीडिएट Python फॉर फाइनेंस

Equality comparisons

  • datetimes
  • संख्याएँ (floats, ints)
  • dictionaries
  • strings
  • लगभग बाकी सब
इंटरमीडिएट Python फॉर फाइनेंस

datetimes की तुलना

date_close_high = datetime(2019, 11, 27)
date_intra_high = datetime(2019, 11, 27)
print(date_close_high == date_intra_high)
True
इंटरमीडिएट Python फॉर फाइनेंस

डिक्शनरी की तुलना

d1 = {'high':56.88, 'low':33.22, 'closing':56.88}
d2 = {'high':56.88, 'low':33.22, 'closing':56.88}
print(d1 == d2)
True
d1 = {'high':56.88, 'low':33.22, 'closing':56.88}
d2 = {'high':56.88, 'low':33.22, 'closing':12.89}
print(d1 == d2)
False
इंटरमीडिएट Python फॉर फाइनेंस

अलग टाइप की तुलना

print(3 == 3.0)
True
print(3 == '3')
False
इंटरमीडिएट Python फॉर फाइनेंस

Not equal ऑपरेटर

print(3 != 4)
True
print(3 != 3)
False
इंटरमीडिएट Python फॉर फाइनेंस

क्रम ऑपरेटर

  • कम <
  • कम या बराबर <=
  • अधिक >
  • अधिक या बराबर >=
इंटरमीडिएट Python फॉर फाइनेंस

Less than ऑपरेटर

print(3 < 4)
True
print(3 < 3.6)
True
print('a' < 'b')
True
इंटरमीडिएट Python फॉर फाइनेंस

Less than ऑपरेटर

date_close_high = datetime(2019, 11, 27)
date_intra_high = datetime(2019, 11, 27)
print(date_close_high < date_intra_high)
False
इंटरमीडिएट Python फॉर फाइनेंस

Less than or equal ऑपरेटर

print(1 <= 4)
True
print(1.0 <= 1)
True
print('e' <= 'a')
False
इंटरमीडिएट Python फॉर फाइनेंस

Greater than ऑपरेटर

print(6 > 5)
print(4 > 4)
True
False
इंटरमीडिएट Python फॉर फाइनेंस

Greater than or equal ऑपरेटर

print(6 >= 5)
print(4 >= 4)
True
True
इंटरमीडिएट Python फॉर फाइनेंस

टाइप्स के बीच क्रम तुलना

print(3.45454 < 90)
True
print('a' < 23)
<hr />----------------------------------------------
TypeError      Traceback (most recent call last)
...
TypeError: '<' not supported between instances of 'str' and 'int'
इंटरमीडिएट Python फॉर फाइनेंस

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

इंटरमीडिएट Python फॉर फाइनेंस

Preparing Video For Download...