- 逻辑判断通常返回结果为布尔值,即True或False
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| In [1]: 1 > 2 Out[1]: False
In [2]: 1 < 2 Out[2]: True
In [3]: 1 <= 2 Out[3]: True
In [4]: 1 >= 2 Out[4]: False
In [5]: 1 == 1 Out[5]: True
In [6]: 1 != 1 Out[6]: False
In [7]: 1 > 2 and 1 == 1 Out[7]: False
In [8]: 1 > 2 or 1 == 1 Out[8]: True
In [9]: not 1 == 1 Out[9]: False
|
input更适合输入数字,输入字符串需要添加引号,内容可以理解为表达式
raw_input更适合输入字符串,输入数字会变为字符串
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| In [10]: input('input:') input:10 Out[10]: 10
In [11]: input('input:') input:abc --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-11-fd51e934a8b5> in <module>() ----> 1 input('input:')
<string> in <module>()
NameError: name 'abc' is not defined
In [12]: input('input:') input:'abc' Out[12]: 'abc'
In [13]: raw_input('input:') input:20 Out[13]: '20'
In [14]: raw_input('input:') input:abc Out[14]: 'abc'
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| In [17]: num1 = input('input a number:') input a number:2
In [18]: num2 = input('input a number:') input a number:3
In [19]: print '%s + %s = %s' % (num1, num2, num1+num2) 2 + 3 = 5
n [20]: num1 = raw_input('input a number:') input a number:2
In [21]: num2 = raw_input('input a number:') input a number:3
In [22]: print '%s + %s = %s' % (num1, num2, num1+num2) 2 + 3 = 23
|