PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 16, 2022

[FIXED] Why is print('a' > 'b') False and print('a' > 'A') True?

 August 16, 2022     ascii, output, python-3.x     No comments   

Issue

When we execute the program print('a' > 'b') it gives us the answer False.

When we execute the program print('a' > 'A') it gives us the answer True.

Please help me with a detailed explanation.


Solution

when comparing characters using the < or > it converts it to an integer.

according to ASCII Table

Meaning:

  • a is 97 decimal
  • b is 98 decimal
  • A is 65 decimal
  • B is 66 decimal

therefor:

print('a' > 'b') is false because print(97 > 98)

and then:

print('a' > 'A') is true because print(97 > 65)



Answered By - Dean Van Greunen
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing