1.整型
2.浮点型
3.字符串类型
4.类型转换
5.如何删除内存中的变量
6.bool类型
1.整型
In [14]: a = 1
In [15]: print(a)
1
In [16]: type(a)
Out[16]: int
2.浮点型
In [17]: b = 1.2
In [18]: type(b)
Out[18]: float
3.字符串类型
In [19]: c = westos
------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-19-47a30bc3df16> in <module>
----> 1 c = westos
NameError: name 'westos' is not defined
In [20]: c = 'westos'
In [21]: type(c)
Out[21]: str
4.类型转换
In [22]: float(a) #整型转换为浮点型
Out[22]: 1.0
In [23]: int(b) #浮点型转换为整型
Out[23]: 1
In [24]: float(c) #字符串‘westos’不能转换为浮点型和整型
------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-24-36b90e4449a0> in <module>
----> 1 float(c)
ValueError: could not convert string to float: 'westos'
In [25]: str(a) #整型转换为字符型
Out[25]: '1'
In [26]: str(b) #浮点型转换为字符串型
Out[26]: '1.2'
In [27]: d = '123456'
In [28]: d
Out[28]: '123456'
In [29]: int(d) #字符串型转换为整型
Out[29]: 123456
In [30]: float(d) #字符串型转换为浮点型
Out[30]: 123456.0
5.如何删除内存中的变量
In [31]: del a
In [32]: a
------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-32-3f786850e387> in <module>
----> 1 a
NameError: name 'a' is not defined
6.bool类型
bool:只有两个值(True False) #非0即真
In [34]: a = 1
In [35]: bool(a)
Out[35]: True
In [36]: bool(0)
Out[36]: False
In [37]: bool(1)
Out[37]: True
In [38]: bool(' ')
Out[38]: True
In [39]: bool('') #空值
Out[39]: False
In [40]: bool(2412414)
Out[40]: True