Python基础_python的数据类型

一、Python 的标准数据类型

二、以下单个实际举例分析数据类型

2.1 python的数字类型

a=100   #整型数据类型
print(type(a))
b=230.32 #浮点数据类型
print(type(b))
c=True ##布尔数据类型
print(type(c))
d=3.43e+4j #复数数据类型
print(type(d))
print(c+a) ##布尔型的数据可以和整型和浮点型的数相加

如上输入结果如下:

2.2  python  中的字符串类型

str1="武汉加油,中国加油"
str2='21'
print(type(str1))
print(type(str2))
print(str1,str2)

运行结果如下:

 2.3  python中的list类型

list1=[12,"我和你","abc","!!"]
list2=[12,4,89]
print(type(list1))
print(type(list2))
print(list1)
输入结果如下:

  2.4  python中的元祖类型

tuple1=(12,"我爱你")
tuple2=(3,) #只有一个元素,需要在元素后添加逗号
tuple3=() #空元祖
print(type(tuple1))
print(tuple1)

输出结果如下:

 2.5  python中的集合类型

set1={"12","78","汉子"}
set2=set()
set3=set("123ee89") #把字符串强制转为集合,相同的e,只保留一个
print(type(set3))
print(set3)
print(set2)
print(type(set2))

2.6 python 中的字典类型

#1、 一般形式创建字典
dic1={}   #定义一个空字典
print(type(dic1))
dic1={"x":2,"y":4}
print(dic1)

输出结果如下:



# 2、使用工厂方法dict()创建字典
dict2=dict([("a1","我爱你"),("a2","早餐")])
print(type(dict2))
print(dict2)
dict3=dict(b1="12",b2="我和你") #采用关键字参数创建字典
print(dict3)

输出结果如下:

猜你喜欢

转载自www.cnblogs.com/123anqier-blog/p/12536888.html