Additioanl notes on comparisons
We have seen how to compare numbers, like x<=3, z>x+y. We can use the larger-than, >, and smaller-than, <, in order to compare strings. The comparison is done by alphabetical order.
Follow these examples in order to answer the questions below.
- The condition ("anaconda" < "elephant") evaluates to TRUE. The comparison is donde letter by letter starting on the left. As 'a' comes first than 'e' in the alphabet, the expression evaluates to TRUE.
- Given x='John' and y='Peter', the condition (x>y) evaluates to FALSE: 'J' comes before 'P', not after, so it is x<y, and that condition is false.
- Given x='abracadabra' and y='abraca', we get the following truth values:
- (x<y) is FALSE
- (x>y) is TRUE
- (x==y) is FALSE