Sunday, 24 November 2019

11th Python program Compare strings

Python string comparison is performed using the characters in both strings. The characters in both strings are compared one by one. When different characters are found then their Unicode value is compared. The character with lower Unicode value is considered to be smaller.


#A  Program

fruit1 = 'Apple'
print(fruit1 == 'Apple')
print(fruit1 != 'Apple')
print(fruit1 < 'Apple')
print(fruit1 > 'Apple')
print(fruit1 <= 'Apple')
print(fruit1 >= 'Apple')

Output
== RESTART: C:/Users/Student/AppData/Local/Programs/Python/Python37-32/t.py ==
True
False
False
False
True
True



#B Program
print('apple' == 'Apple')
print('apple' > 'Apple')
print('A unicode is', ord('A'), ',a unicode is', ord('a'))


Output
== RESTART: C:/Users/Student/AppData/Local/Programs/Python/Python37-32/t.py ==
False
True
A unicode is 65 ,a unicode is 97

#Note: ord() function to print the Unicode code point value of the characters.

No comments:

Post a Comment