+ 3
The min function ( Python )
What would happen if I used the min function when there is a list of strings and no numbers?
3 odpowiedzi
+ 2
It returns the smallest string. Strings are compared lexicographically, that means the smallest string is the first in alphabetical ordering.
min(["Sololearn", "Python", "Questions"]) returns Python
+ 1
If there are only strings in it, it compares the strings. If you have mixed types convert them with str() or int() or it failes.
+ 1
What about just trying it in the code playground? ;)
You will then notice, that the string which comes alphabetically first is chosen.
So e.g. for ["bla","gibberish"]
the min function will output bla.
If I'm not mistaken it is also part in the Python course. Or maybe only at sorting 🤔 I don't know anymore 😅