9 月 252020
 
>>> #多条件比较,先给变量赋值,再多条件比较
>>> middle = 5
>>> 1 < middle < 10
True
>>> #变量比较
>>> two = 1 + 1
>>> three = 1 + 3
>>> two < three
True
>>> #字符串比较
>>> 'Eddie Van Helen' == 'eddie van helen'
False
>>> #两个函数结果比较
>>> abs(-10) > len('length of this word')  
False
>>> #不同类型的对象不能使用“<”,“>”,“<=”,“>=”进行比较,但可以使用“==”,“!=”
>>> 42 > 'the answer'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'int' and 'str'
>>> 42 == 'the answer'
False
>>> 42 != 'the answer'
True
>>> 5.0 == 5
True
>>> 3.0 > 1
True
>>> # True = 1 与 False = 0
>>> True > False
True
>>> True + False > False + False
True
>>>

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)