开发者

what is the usefulness of '>' in python

开发者 https://www.devze.com 2022-12-20 04:46 出处:网络
print \'xxx\' > \'ssaw开发者_运维问答w\' it print \'true\' who can give me a clear example . thanksJust like in math, > compares two operands and returns True if the left operand is greater
print 'xxx' > 'ssaw开发者_运维问答w'

it print 'true'

who can give me a clear example .

thanks


Just like in math, > compares two operands and returns True if the left operand is greater than the right, otherwise False.


In python strings are ordered lexicographically.


you can test it out on the interpreter

>>> 'xxx'>'yyy'  #first character 'x' is less than first character 'y', so false
False
>>> 'xxx'>'xyy' 
False
>>> 'xyy'>'xyx' #3rd character 'y' is greater than 3rd character 'x', so true
True


to order strings syntactically (e.g. alphabetically).


It can do y>x>z as a nicer way to say y>x and x>z.

As others have mentioned its a simple greater-than comparison (in your case for strings).

0

精彩评论

暂无评论...
验证码 换一张
取 消