In [1]: #欢迎来到“只读课堂”!
...: #今天呢,我来讲点儿深入的知识:变量
...:
...: #变量类型:
...: #1.字符串 str
...: #2.数字 int float complex ...
...: #3.列表 list
...: #4.元组 tuple
...: #5.字典 dict
...:
In [2]: #数值类型:
In [3]: number = 10
In [4]: number = number + 10
In [5]: number += 10
In [6]: #上面也属于“增值运算”
In [7]: #也可以表示为:
In [8]: number -= 10
In [9]: number *= 10
In [10]: number /=10
In [11]: #接下来我来介绍一下python变量中最重要的:bool型
In [12]: #它主要由True,False组成
In [13]: (True, False)
Out[13]: (True, False)
In [14]: True == 1
Out[14]: True
In [15]: false ==0
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-15-ec417c4a1d18> in <module>()
----> 1 false ==0
NameError: name 'false' is not defined
In [16]: #打错了
In [17]: False == 0
Out[17]: True
In [18]: #看到还是True,以上就是公式了
In [19]: #再举一些例子:
In [20]: True + 10
Out[20]: 11
In [21]: 100 > 10
Out[21]: True
In [22]: 100 < 10
Out[22]: False
In [23]: #我们可以这样运用
In [24]: #当然,bool类型还可以做为运算:与运算、或运算、非运算
In [25]: True and True
Out[25]: True
In [26]: #它的意思就是说,两个值都为True的时候,才会是True,真真=真。这就是“与运算”:同为真,则为真。
In [27]: #或运算:至少有一个为真,就为真:
In [28]: True and False
Out[28]: False
In [29]: 打错了
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-29-8323f3b2bcbb> in <module>()
----> 1 打错了
NameError: name '打错了' is not defined
In [30]: True or False
Out[30]: True
In [31]: False or True
Out[31]: True
In [32]: #注意,这些运算是严格区分大小写的
In [33]: #非运算
In [34]: not Flase
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-34-e6b670d201f8> in <module>()
----> 1 not Flase
NameError: name 'Flase' is not defined
In [35]: not False
Out[35]: True
In [36]: not True
Out[36]: False
In [37]: #非运算就是取相反值
In [38]: #| 操作符 | 解释 |
In [39]: #| < | 小于 |
In [40]: #| <= |小于等于|
In [41]: #| > | 大于 |
In [42]: #| >= |大于等于|
In [43]: #| == | 等于 |
In [44]: #| != |不等于|
In [45]: #| is |是相同对象|
In [46]: #“is”就是判断两个对象中是不是同一个对象
In [47]: #最终这些操作符都是会输出True或False。好了,变量中的操作符已经全列出来了,快去试试!
In [48]: print("本次“只读课堂”的python课程就到这里了,欢迎继续收看!")
本次“只读课堂”的python课程就到这里了,欢迎继续收看!