CBSE Class 12 Computer Science Question 32 of 120

Review of Python Basics — Question 6

Back to all questions
6
Question

Question 6

The statement: bval = str1 > str2 shall return ............... as the output if two strings str1 and str2 contains "Delhi" and "New Delhi".

  1. True
  2. Delhi
  3. New Delhi
  4. False
Answer

False

Reason — Python's lexicographical comparison compares strings character by character based on their ASCII values. In the case of "Delhi" and "New Delhi", the comparison stops at the first difference encountered, which is the comparison between 'D' and 'N'. Since 'N' has a greater ASCII value than 'D', the lexicographical comparison returns False.