-2

Is '2' > '10'? What is the output if we compare two integers which are converted to string format?

I am getting true but it's false, right?

enter image description here

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
naveen
  • 23
  • 5

1 Answers1

1

When comparing strings, you compare them lexicographically. The character 2 comes after the character 1, so the result is True. The fact that these two strings could be converted to integers is inconsequential.

Mureinik
  • 277,661
  • 50
  • 283
  • 320