Python教程 not运算符

时间:2024-10-13 05:36:44

1、新建一个not运算符.py 文件,如图所示:

Python教程 not运算符

2、设置脚本文件的编码:# coding=gbk,如图所示:

Python教程 not运算符

3、not运算符的作用:对x进行布尔取反操作,语法如图所示:

Python教程 not运算符

4、定义一个布尔变量 x,并且赋值为True,代码如图所示:

Python教程 not运算符

5、使用 type() 函数获取此时变量 x 的类型,如图所示:

Python教程 not运算符

6、对变量进行取反操作,代码:not x,然后输出其值,如图所示:

Python教程 not运算符
© 手抄报圈