अजगर श्रृंखलित तुलना के साथ विशेष काम करता है। हालांकि
x > y > z # in this case, if x > y evaluates to true, then
# the value of y is being used to compare, again,
# to z
(x > y) > z # the parenth form, on the other hand, will first
# evaluate x > y. And, compare the evaluated result
# with z, which can be "True > z" or "False > z"
दोनों ही मामलों में, यदि पहली तुलना False
है, बयान के बाकी को देखा नहीं किया जाएगा:
निम्नलिखित अलग ढंग से मूल्यांकन किया जाता है।
अपने विशेष मामले के लिए,
1 in [] in 'a' # this is false because 1 is not in []
(1 in []) in a # this gives an error because we are
# essentially doing this: False in 'a'
1 in ([] in 'a') # this fails because you cannot do
# [] in 'a'
इसके अलावा ऊपर पहला नियम प्रदर्शित करने के लिए, इन बयानों कि यह सच है के रूप में मूल्यांकित कर रहे हैं।
1 in [1,2] in [4,[1,2]] # But "1 in [4,[1,2]]" is False
2 <4> 1 # and note "2 < 1" is also not true
अजगर ऑपरेटरों की वरीयता: http://docs.python.org/reference/expressions.html#summary
स्रोत
2012-09-30 11:41:59
आप शायद यहां वर्णित व्यवहार को मार रहे हैं: http://docs.python.org/reference/expressions.html#not-in, वह आपको लिखने देता है 'यदि कोई millimoose
@millimoose काम करता है: हाँ, मैंने कभी भी "तुलना" ऑपरेटर के रूप में 'इन' के बारे में सोचा नहीं। : \ – Mehrdad
हाय [पाइथन दुभाषिया में किस प्रकार का पार्सर उपयोग किया जाता है?] (Http://stackoverflow.com/questions/15532616/what-type-of-parser-is-used-in-python-interpreter) –