Page 230 - Robotics and AI class 10
P. 230
Relational/Comparison Operators
All relational operators (>,<,>=,<=,==,!=) can be used to compare two strings and returns either True or False.
The comparison is done character by character based on the ASCII/Unicode.
For example:
>>> 'a'=='a'
True
>>> 'a'=='A"
False
>>> 'abc'=='abc'
True
>>> 'abc'>'abC'
True
>>> 'hi'!=Hi"
True
>>> 'abc'<='abc'
True
The ASCII/Unicode values of:
● Digits: 0 to 9 is from 48 to 57
● Uppercase: ‘A’ to ‘Z’ is from 65 to 90
● Lowercase: ‘a’ to ‘z’ is from 97 to 122
Python built in functions used to find:
● the ASCII/Unicode is
ord('a')
Output:
97
ord('8')
Output:
56
● the character of the Unicode can be given by using:
chr(56)
Output:
'8'
chr(71)
Output:
'G'
String Slicing
String Slicing means referring to a part of the string. It is the process of extracting a range of characters from a
given string.
228 Touchpad Robotics & Artificial Intelligence-X

