Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8698555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:45:21+00:00 2026-06-13T01:45:21+00:00

why python is giving output like this: >>> ‘apple’ > ‘T’ True >>> ‘apple’

  • 0

why python is giving output like this:

>>> 'apple' > 'T'
True
>>> 'apple' > 't'
False

It should be True for both cases.right?

Edit:

I got the Idea of ASCII Table.Thanks!!

Now what about this.Is 11.1 is being treated as ‘11.1’?

>>> 'apple' > 11.1
True
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:45:22+00:00Added an answer on June 13, 2026 at 1:45 am

    The key insight here is that string comparison doesn’t compare based on alphabetical order or any natural order, but instead on the order of the characters in ASCII. You can see this order in an ASCII table.

    Python will compare the first character in each string, and if it is the same will move on to the next. It will do this until the characters differ, or one string runs out (in which case the longer string will be considered greater).

    As cdhowie pointed out, in a decimal ASCII encoding T is 84, a is 97, and t is 116. Therefore:

    >>> 'T' < 'a' < 't'
    True
    

    To show our second point:

    >>> "apple" > "a"
    True
    

    To get a more natural comparison see: Does Python have a built in function for string natural sort?

    To answer the question you added in an edit:

    The simple answer is “yes”. A conversion of 11.1 to '11.1' is being performed.

    The more complicated answer deals with how exactly comparison is implemented in python. Python objects can be compared if they implement the Comparison magic methods. There’s a fair amount of reading you can do about python internals in that link.

    As @glibdup pointed out, the above is incorrect. In python different types are compared based on the name of their type. So, since 'str' > 'float' any string will be greater than any float. Alternatively, any tuple will be greater than any string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is Pydev giving me syntax errors for built-in python functions like str()? Undefined
Hi I m trying to execute small code in python , it is giving
Python allows aliasing of imports, through ...as <ALIAS> clauses in the import statement, like
I am learning python, now, i came across a code snippet which looks like
The python manage.py syncdb command is giving me the following error: sqlite3.OperationalError: unable to
value = [python:guru-age20, is_it_possible_time100:goodTime99, hmm_hope_no_onecanansswer] How to get a particular string from this list
Trying to run a MySQL script via Python and it keeps giving me errors.
I am having some trouble with Python giving me a result I do not
I'm working on giving a python server a GUI with tkinter by passing the
This is a followup to Multi-dimensional char array (array of strings) in python ctypes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.