making string comparision in python

前端 未结 2 1429
一整个雨季
一整个雨季 2021-01-29 14:03

I was trying to replicate the strcmp from c in python.I typed the former program and it worked but the latter seems to work as well?please explain the latter one.I only expected

2条回答
  •  野性不改
    2021-01-29 14:16

    Former one just compares the length of two strings. But latter one try to find which one is bigger. For instance:

    A = "abcdef"
    B = "b"
    

    len(A) > len(B) will be true But B > A will be true, because "b" > "a" (which is the first letter of A)

提交回复
热议问题