Python 3逻辑未将True返回为True

时间:2018-10-01 14:32:56

标签: python python-3.x boolean logical-or logical-and

在尝试学习Python时,我一直在使用教程和自己的教程编写代码。我正在使用Python3。

正在执行以下操作的代码段:

>>>print(not 1 == 1 or 6 == 6 and 9 == 9)  
True

我已经运行了这段代码的各个部分。似乎OR运算符正在使用双精度True取反。 (不是True或True)输出True而不是False? or运算符不是要得出第一个True的结论,而not运算符是否要得出True为False的结论?

1 个答案:

答案 0 :(得分:3)

您应该查看operator precedence

让我们检查一下此表达式并根据其优先级来处理每个运算符:

import Vue from 'vue'
import MyComponent from '../myComponent/' // <-- Need to fire the event here 
import router from './router'

Vue.use(MyComponent)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
}).$mount('#app')

首先,执行not 1 == 1 or 6 == 6 and 9 == 9 运算符,因此我们得到:

==

然后,not True or True and True 运算符:

not

然后,False or True and True 运算符:

and

然后,False or True 运算符,产生您所看到的结果:

or
相关问题