三、数据类型

54 阅读1分钟

一 、认识数据类型

在Python里为了应对不同的业务需求,也把数据分为不同的类型。 1666613276883.jpg

1、按经验将不同的变量储存不同的类型的数据

2、验证这些数据到底是什么类型 -- 检测数据类型 -- type()


   num1= 1
   num2=1.2
   a='hello world'
   b=True
   c=[10,20,30]
   d=(10,20,30)
   e={10,20,30}
   f={'name':'Tom','age':16}
   
   print(tpye(num1))  // int     ---整型
   print(tpye(num2))  // float   ---浮点型 就是小数
   print(tpye(a))     // str     ---字符串
   print(tpye(b))     // bool    ---布尔型,通知判断使用,布尔值有两个值 TrueFalse
   print(tpye(c))     // list    ---列表
   print(tpye(d))     // tuple   ---元祖
   print(tpye(e))     // set     ---集合
   print(tpye(f))     // dict    ---字典