
1.Python 3 主要有6种标准数据类型
-
Number(数字)
-
String(字符串)
-
List(列表)
-
Tuple(元组)
-
Set(集合)
-
Dictionary(字典)
2.Number 类型
-
Number(数字):int(整数)、float(浮点数),bool(布尔类型)
-
在 python3 中 bool 是 int 的子类,True 和 False 这两个布尔类型可以参与数字运算,True 转换为1,False转换为0
# 整型num = 123# 浮点型float1 = 9.43# 布尔类型,首字母大写bool1 = Truebool2 = Falseprint(num,float1,bool1,bool2)# type() 可以用来查看变量的数据类型# <class 'int'>print(type(num))# <class 'float'>print(type(float1))# <class 'bool'>print(type(bool1))
3.String 类型
-
String(字符串):字符串是有数字、字母、下划线、汉字等组成的字符串,一般是使用 '' 或者 "" 或者 ''' 文本 ''' 或者 """ 文本 """
str1 = "hello"str2 = 'world'str3 = '''床前明月光,疑是地上霜。举头望明月,低头思故乡。'''str4 = """床前明月光,疑是地上霜。举头望明月,低头思故乡。"""print(str1,str2,str3,str4)# <class 'str'>print(type(str1))
4.List 类型
-
List(列表):列表使用 [] 来定义,它支持数字、字符串、甚至还可以是列表(嵌套)
list1 = ['古天乐', '吴京', '李晨', '陈凯歌', "徐克"]print(list1)# <class 'list'>print(type(list1))# list 中可以存放不同的数据类型list2 = [12, 34, 56, 5.12, True, False, "hello"]print(list2)# list 中可以嵌套listlist3 = [87, 32, 9.34, True, [45, 40, 8.34, False]]print(list3)
5.Tuple 类型
-
Tuple(元组):元组使用 () 来定义,它支持数字、字符串、还可以嵌套元组,类似于列表
-
元组中的元素不能修改,不能删除
tuple1 = (12, 34343, 4.43, 'world', True)print(tuple1)# <class 'tuple'>print(type(tuple1))
6.Set 类型
-
Set(集合):表示集合类型,集合使用 {} 来定义,里面只有值,没有索引
set1 = {123, 54, 6.53, True, False, 'apple'}print(set1)# <class 'set'>print(type(set1))
7.Dictionary 类型
-
Dictionary(字典):表示字典类型,字典使用 {} 来定义,字典是由 key 和 value 组成,例如:{key1:value1,key2:value2,key3:value3,...}
dict1 = {'name':'tfos', 'age':18, 'height':178}print(dict1)# <class 'dict'>print(type(dict1))



















