Advertisements
Advertisements
प्रश्न
Explain in detail about cmp() function.
स्पष्ट करा
Advertisements
उत्तर
cmp()was a Python 2 function used to compare two objects, including dictionaries and tuples.- Its historical form was
cmp(x, y). - It returned:
0whenxandywere equal.- A positive value when
xwas greater thany. - A negative value when
xwas less thany.
- From the source examples:
cmp(month, m)returns0when both dictionaries are the same;cmp(m, n)returns1; andcmp(n, m)returns-1. cmp()was removed in Python 3. Use comparison operators instead:x == yfor equality.x > yto check whetherxis greater thany.x < yto check whetherxis less thany.
- A Python 3 equivalent returning
-1,0, or1is:
result = (x > y) - (x < y)
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
