Python标准数据类型:Numbers数字,String字符串,List列表,Tuple元祖,Dict字典
Numbers数字:int整型,long长整型,float浮点型,complex复数
a1 = 5 a2 = 5.5 print(a1,type(a1)) print(a2,type(a2))
String字符串:
a3 = "hello world!" a4 = 'hello world!' a5 = '''hello world!''' a6 = ''' hello world! ''' a7 = "hello world!" print(a3,type(a3)) print(a4) print(a5) print(a6) print(a7)
hello world! <class 'str'> hello world! hello world! hello world! hello world!注意:单引号和双引号是一样的,三引号'''''''或者""""""表示多行字符,从'''开始就是第一行,末尾'''表示最后一行
bool布尔型:True,False
a8 = True print(a8,type(a8)) print(True == 1) print(False == 0) print(True * 100)
True <class 'bool'> True True 100其中True表示1,False表示0
List列表:支持字符,数字,字符串以及包含列表(即嵌套),用[]标识,有序对象
a9 = [1,'a',2.4,111,3,[1,2,3]] print(a9,type(a9))
[1, 'a', 2.4, 111, 3, [1, 2, 3]] <class 'list'>Tuple元祖:用()标识,不能二次赋值,可以理解为不可变的列表(只读列表)
a10 = (1,2,3,[1,2,3],'hahaha') print(a10,type(a10))
(1, 2, 3, [1, 2, 3], 'hahaha') <class 'tuple'>Dict字典:用{}标识,由索引(key)和它对应的值(value)组成,无序对象
a11 = {"name":"gongpeiyuan","age":20,"score":(100,100,100)} print(a11,type(a11))
{'name': 'gongpeiyuan', 'score': (100, 100, 100), 'age': 20} <class 'dict'>