Why does the Max of my tuples return yellow? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why does the Max of my tuples return yellow?

Trying to understand how the different functions and methods work within python. So I wanted to experiment and see what happens with the below code. However, I am really struggling to figure out why ''' print(max(colours)) ''' equates to yellow. input >colours = ("black", "red", "green","yellow","purple", "orange") >print(colours[0]) >print(max(colours)) Output > black > yellow

17th Mar 2018, 12:38 PM
Pedro Dias
Pedro Dias - avatar
3 Answers
+ 10
the comparison is done lexicographically for strings so yellow (which starts with 'y' has the highest value)
17th Mar 2018, 1:28 PM
Burey
Burey - avatar
+ 3
👍
17th Mar 2018, 2:21 PM
Burey
Burey - avatar
0
thank you so much for the swift reply, and of course!!!
17th Mar 2018, 2:16 PM
Pedro Dias
Pedro Dias - avatar