开发者

what is the usefulness of '>' in python

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜