---
title: "Discussion on \"Understanding String Comparison in Python: Why 'hello' <= 'hi' is True\" | Hashnode"
description: "Discussion on \"Understanding String Comparison in Python: Why 'hello' <= 'hi' is True\". Python for Beginners"
url: "https://hashnode.com/posts/understanding-string-comparison-in-python-why-hello-hi-is-true/66f8f5896b3d38272d8ea862"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Understanding String Comparison in Python: Why 'hello' <= 'hi' is True](https://ahnaftahmidzaman.hashnode.dev/understanding-string-comparison-in-python-why-hello-hi-is-true?utm_source=hashnode&utm_medium=feed)

Python for Beginners

Sep 29, 2024 · 3 min read · ahnaftahmidzaman.hashnode.dev  
Read the article

-   [#string-comparison](https://hashnode.com/tag/string-comparison)
-   [#lexicographical-order](https://hashnode.com/tag/lexicographical-order)
-   [#python-comparisons](https://hashnode.com/tag/python-comparisons)
-   [#python](https://hashnode.com/tag/python)
-   [#unicode](https://hashnode.com/tag/unicode)
-   [#python-tips](https://hashnode.com/tag/python-tips)
-   [#programming-fundamentals](https://hashnode.com/tag/programming-fundamentals)
-   [#python-string](https://hashnode.com/tag/python-string)
-   [#python-operators](https://hashnode.com/tag/python-operators)
-   [#codingtutorial](https://hashnode.com/tag/codingtutorial)

## Written by

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

@AhnafTahmidZaman · Dhaka, Bangladesh

  
[View profile](https://hashnode.com/@AhnafTahmidZaman)

Pursuing Computer Science and Engineering Degree

## Responses 4

Markdown supported · ⌘↵ to post

[lilywilsaon](https://hashnode.com/@wilsonw)

[3d ago](https://hashnode.com/posts/understanding-string-comparison-in-python-why-hello-hi-is-true/66f8f5896b3d38272d8ea862/comment/6afb3d6146190e8d6cf329b0)

I’ve also just started learning Python; thanks for sharing.

[Player Pure](https://hashnode.com/@escape-room)

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

I’ve also just started learning Python; thanks for sharing. [Mr Flip](https://mrflip.app/)

[angelapick](https://hashnode.com/@angelapick)

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

I've just started learning Python, but I find the language quite complex. Thanks for your sharing.

[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.
