मराठी

Explain in detail about cmp() function.

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:
    • 0 when x and y were equal.
    • A positive value when x was greater than y.
    • A negative value when x was less than y.
  • From the source examples: cmp(month, m) returns 0 when both dictionaries are the same; cmp(m, n) returns 1; and cmp(n, m) returns -1.
  • cmp() was removed in Python 3. Use comparison operators instead:
    • x == y for equality.
    • x > y to check whether x is greater than y.
    • x < y to check whether x is less than y.
  • A Python 3 equivalent returning -1, 0, or 1 is:
result = (x > y) - (x < y)
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1: Review of Phython - EXERCISE [पृष्ठ २७]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 1 Review of Phython
EXERCISE | Q 31. | पृष्ठ २७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×