-1

What exactly is the meaning of comparing one string to another using greater (>) or lesser (<) operators and get true of false, like in this code:

shopping_list=['heineken', 'patagonia', 'backer', 'austria', 'heisenbhan']

im_drinking='heineken'

for beer in shopping_list:
    if beer==im_drinking:
        print('yes, special one.')
    elif beer>im_drinking:
        print('good one')
    else:
        print('not this one, but I like it to')

this was the result when I ran the code:

yes, special one.
good one
not this one, but I like it to
not this one, but I like it to
good one

1 Answers1

0

Suppose you have str1 as "Jane" and str2 as "Jake" . The first two characters from str1 and str2 ( J and J ) are compared. As they are equal, the second two characters are compared. Because they are also equal, the third two characters ( n and k ) are compared. And because 'n' has greater ASCII value than 'k' , str1 is greater than str2 .

gmed
  • 140
  • 1
  • 10