+ 1

When using boolean operators in python, what is the point of using Unicode or "ASCII" in a string?

# The greater than > operator checks if the left string has a higher # Unicode value than the right string. If true, the Python interpreter # returns a True result. Since W has a Unicode value of 87, and you can # easily calculate that F has a Unicode value of 70, this comparison is # the same as 87 > 70. As this is true, Python will return a True # result. print("Wednesday" > "Friday") True # The less than < operator checks if the left string has a lower # Unicode value than the right string. If you reference the Unicode # chart above, you can see that all lowercase letters have higher # Unicode values than uppercase letters. We can see that B has a # Unicode value of 66 and b has a Unicode value of 98. This # comparison is the same as 66 < 98, which is true. So, Python will # return a True result. print("Brown" < "brown") True

16th Jun 2024, 2:01 AM
Byron
Byron - avatar
5 Respostas
+ 6
Byron , Unicode is a *superset* of ASCII, and the numbers 0–127 have the same meaning in ASCII as they have in Unicode. For example, the number 65 means "Latin capital 'A'". (source: stackoverflow.com)
16th Jun 2024, 9:59 AM
Lothar
Lothar - avatar
+ 5
Hi Byron, Boolean operators are and, or, and not. However, in your question, you are referring to comparison operators. When using comparison operators in Python to compare strings, the comparison is based on their Unicode values. Unicode and ASCII provide standard numeric values for characters, making comparisons consistent. For example, in: >>> "Wednesday" > "Friday" it compares ‘W’ (87) and ‘F’ (70), so it returns True. Similarly: >>> "Brown" < "brown" compares ‘B’ (66) and ‘b’ (98), returning True. Use ord() to find a character’s Unicode value to understand these comparisons.
16th Jun 2024, 5:25 AM
Per Bratthammar
Per Bratthammar - avatar
+ 1
I was just putting that in as an example, I already know how to use them, I was just wondering what the point is behind using them.
16th Jun 2024, 2:31 AM
Byron
Byron - avatar
0
Pasting a mass of python docs into your question body with little to no explanation is not very helpful..
16th Jun 2024, 2:11 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
Lothar Byron fun fact, Unicode was made a superset of ASCII to be backwards compatible. ASCII is the older encoding, but couldn’t work for non-english characters.
16th Jun 2024, 3:43 PM
Wilbur Jaywright
Wilbur Jaywright - avatar