Python基础-python的数据类型

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

类型转换

 In [22]: float(a)                                                       
 Out[22]: 1.0

 In [23]: int(b)                                                         
 Out[23]: 1

 In [24]: float(c)                                                       
 ------------------------------------------------------------------------
 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

如何删除内存中的变量

 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

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值