04 Python 类型

原生类型

    1.布尔类型,bool

    数值类型

        2.整型,int

        3.浮点型, float

            分数 

        4.复数,complex

    4.列表,list

    5.元组,tuple

    6.集合,set

    7.词典,dict

    8.None

    9.字符串,str

    10. bytes

整型,浮点,字符串类型变量定义:

    i = int(4)          或者 i = 10
    f = float(2.9)      或者 f = 2.9
    mystr = string("hello world")  或者 mystr = "hello world"


list:    



       使用 [ ] 来定义 list:

    a_list = ['a','b','hello world', 5, 5.3, 80]

        构造函数的方式定义list:

    a_list = list(['a','b',50, 2.5, "hello world"])

    list中元素的引用:

    采用下标的方式来引用list中的元素:

 a_list[0] 
 a_list[-1]    #表示访问list中的最后一个元素

tuple

    使用  ( ) 来定义tuple:

 a_tuple = ('a','b','Hello world',51, 2.5)

    构造函数方式定义 tuple:

 b_tuple = tuple( ('a','b','Hello world',5, 1.5) )

    tuple中元素的引用:

 a_tuple[2]
 a_tuple[-1]    #表示引用 tuple中的最后一个元素


你可能感兴趣的:(04 Python 类型)