In Python, you can do this:

"ab" > "ac"

which returns False.

In Mathematica, it doesn't evaluate.

But why? These are literal strings, not symbols.

  • 2
    $\begingroup$ Just from the question description, I can not figure out what is comparing two strings. $\endgroup$ – Αλέξανδρος Ζεγγ Mar 21 '20 at 8:57
  • 1
    $\begingroup$ But 1>2 works, there's also no indication of what is comparing two numbers. $\endgroup$ – liang Mar 21 '20 at 9:09
  • $\begingroup$ With due respect, comparison of two numbers is common sense taught as early as in primary mathematics, but that of strings is not. $\endgroup$ – Αλέξανδρος Ζεγγ Mar 21 '20 at 13:44
  • $\begingroup$ Number and string are both "atoms" in the language, so why are they treated differently in this case? Just because one is taught in primary school, and the other is not? Just wondering if there's a deeper reason for that. It seems odd a programming language would depend its design on school curriculum, rather than its own construct. $\endgroup$ – liang Mar 22 '20 at 3:26
  • $\begingroup$ If strings should be comparable in the way of numbers, just because both of them are "atoms", so should symbols. Maybe this question should be forwarded to Wolfram himself :). $\endgroup$ – Αλέξανδρος Ζεγγ Mar 22 '20 at 3:36

AlphabeticOrder can compare strings alphabetically (or by other conventions used in dictionaries by various languages).

  • $\begingroup$ While alphabetical ordering is works great for this simple example, things start to get weird once you cross into alpha-numeric strings. For that, you need lexicographic ordering. $\endgroup$ – AxGryndr Mar 22 '20 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.