---
title: "Comment by Mary Lindsey on \"Understanding String Comparison in Python: Why 'hello' <= 'hi' is True\" | Hashnode"
description: "How does this lexicographical comparison work with longer strings? Edited by slope game 1 day ago"
url: "https://hashnode.com/posts/understanding-string-comparison-in-python-why-hello-hi-is-true/66f8f5896b3d38272d8ea862/comment/673edbb21455d7034783f7b4"
---

[Discussion](https://hashnode.com/posts/understanding-string-comparison-in-python-why-hello-hi-is-true/66f8f5896b3d38272d8ea862)

Comment [Understanding String Comparison in Python: Why 'hello' <= 'hi' is True](https://hashnode.com/posts/understanding-string-comparison-in-python-why-hello-hi-is-true/66f8f5896b3d38272d8ea862)

[Mary Lindsey](https://hashnode.com/@marylindsey)

[Nov 21, 2024](https://hashnode.com/posts/understanding-string-comparison-in-python-why-hello-hi-is-true/66f8f5896b3d38272d8ea862/comment/673edbb21455d7034783f7b4)

How does this lexicographical comparison work with longer strings?

Edited by [slope game](https://slope3.com/) 1 day ago

[Ahnaf Tahmid Zaman](https://hashnode.com/@AhnafTahmidZaman)

[Nov 21, 2024](https://hashnode.com/posts/understanding-string-comparison-in-python-why-hello-hi-is-true/66f8f5896b3d38272d8ea862/comment/673edbb21455d7034783f7b4#reply-673edda09908a74a7e1e2f90)

In Python, lexicographical comparison works the same for longer strings. For example, comparing "Alice Wonderland" and "Bob Marley", Python compares characters one by one. The first character 'A' (65) in "Alice" is smaller than 'B' (66) in "Bob", so "Alice Wonderland" is considered less. If characters match, it continues to the next character until a difference is found or one string runs out of characters.
