educative.io

String Operations - Learn Python 3 from Scratch

The code is written in Python

1: house = "Gryffindor"
2: house_copy = "Gryffindor"
3: print(house == house_copy)
4: new_house = "Slytherin"
5: print(new_house <= house)
6: print(new_house >= house

The output of the above code is:

True
False
True

My question is on what basis line 5, line 6 are executed ? I mean on what basis this 2 string are compared ?

Hi Debangaraz,
Python string comparison compares each character in both strings individually. When multiple characters are discovered, their Unicode code point values are compared. Characters with lower Unicode values are considered smaller.

Happy learning!