This is a python statement that uses RELATIONAL OPERATORS:
>>> 'Hello'<'Goodbye
False
>>> 'Goodbye'<'Hello'
True
Please explain why is 'Hello'<'Goodbye' in python.
[[ Topic: relational operators in python ]]
{{{ Note: Pls post relevant answers }}}
Answers
"Hello" < "Goodbye"
This is false, because when using relational operators like "<", ">", "<=", ">=", etc, Python compares the ASCII values of the characters.
ASCII values are reserved numbers that represent each character.
If we were to continue like this, Z's ASCII value would be 90.
It needs to be kept in mind that the values mentioned above, are only for the uppercase versions of the characters.
- Lower case a - z would have ASCII values starting from 97 - 122.
- Numbers 0 - 9 would have ASCII values starting from 49 - 57.
- Special characters [!, %, $, #, @, etc] also have ASCII values.
Since H has a greater ASCII value than G, "Hello" < "Goodbye" would be false.
♣ Qᴜᴇꜱᴛɪᴏɴ :
>>> 'Hello'<'Goodbye
False
>>> 'Goodbye'<'Hello'
True
ʜᴏᴡ ᴛʜɪꜱ ɪꜱ ᴅᴏɴᴇ ?
♣ ᴀɴꜱᴡᴇʀ :
ʙᴇꜰᴏʀᴇ ɢᴇᴛᴛɪɴɢ ᴛᴏ ᴛʜᴇ ᴄᴏɴᴄᴇᴘᴛ ᴏꜰ ᴛʜɪꜱ Qᴜᴇꜱᴛɪᴏɴ,ʏᴏᴜ ɴᴇᴇᴅ ᴛᴏ ᴋɴᴏᴡ ᴀʙᴏᴜᴛ ᴀꜱᴄɪɪ ᴠᴀʟᴜᴇꜱ
ᴀꜱᴄɪɪ ꜱᴛᴀɴᴅ ꜰᴏʀ ᴀᴍᴇʀɪᴄᴀɴ ꜱᴛᴀɴᴅᴀʀᴅ ᴄᴏᴅᴇ ꜰᴏʀ ɪɴꜰᴏʀᴍᴀᴛɪᴏɴ ɪɴᴛᴇʀᴇxᴄʜᴀɴɢᴇ
ASCII is a 7-bit code
The code consists of 33 non-printable and 95 printable characters and includes both letters, punctuation marks, numbers and control characters
__________________________
Going to Question :
ᴀꜱᴄɪɪ ᴠᴀʟᴜᴇꜱ ᴄᴀɴ ʙᴇ ꜰᴏᴜɴᴅ ɪɴ ᴘʏᴛʜᴏɴ ɪᴛꜱᴇʟꜰ ᴜꜱɪɴɢ ᴛʜɪꜱ ᴄᴏᴅᴇ :
Brainly = input("Enter any character: ")
print("The ASCII value of char " + Brainly + " is: ",ord(Brainly))
With This we can find ASCII value of A is 65,B is 66 and so on.
The ASCII value of G is 71 and that of H is 72
While comparing this - we say 72 > 71 or 71 < 72
Which means H > G or G < H
'Hello'<'Goodbye' shows :
H < G, which is false
'Goodbye'<'Hello' shows :
G < H which is true
Hope my answer will help
I am also attaching some attachments which may help