+ 1

How does string compare work in Python ?

How does string compare work in Python ? For example - ("ten" == "six") what is the output of this compare ?

5th Nov 2016, 9:01 AM
Akash A
4 Answers
+ 2
It depends where you are using it. If you used it in an if statement, the code within would not execute. Example if 'ten' == 'six': print("True") else: print('False') Your output, if just ran as a line of code would output as False. >>> 'ten' == 'six' False
5th Nov 2016, 9:10 AM
Harry Pearson
Harry Pearson - avatar
+ 2
Yes it works. comparing Strings gives you a boolean statement of True or False.
5th Nov 2016, 10:36 AM
Niklar
Niklar - avatar
+ 2
but how does the compare happen in a sys s/w perspective ? or in-terms of a h/w processor ?
5th Nov 2016, 5:44 PM
Akash A
0
it compares the ASCII codes
5th Nov 2016, 6:10 PM
Sandeep Taksande
Sandeep Taksande - avatar