Python基本数据类型

作者: 三不小青年 | 来源:发表于2018-08-14 19:19 被阅读11次
    Python基本数据类型

    #数据类型:整形,浮点,字符串,布尔

    #ython把0、空字符串''和None看成 False,其他数值和非空字符串都看成 True

    print(45678+0x12fd2)

    print(11.2+10.00)

    print('learn Python in imooc')

    print(0xff==255)

    #字符串'.号'表空格

    print('hello, python')

    print('hello,','python')

    #字符串,转义符号,r'''...'''

    s ='Python was started in 1989 by \"Guido\".\nPython is free and easy to learn.'

    print(s)

    print (r'''"To be, or not to be": that is the question.

    Whether it's nobler in the mind to suffer.''')

    #字符串运算

    s="bai"

    s1="wuguang"

    print(s[0:-1]);

    print(s+s1);

    #变量,范类型

    x1=1

    d=3

    n=100

    x100=x1+(n-1)*d

    s=(x1+x100)*n/2

    print(s)

    #list

    li=['新月打击','苍白之瀑','月神降临','月神冲刺'];

    print(li[0:2])

    print(li[-1])#打印出单个

    print(li[-1:])#打印出列表

    print(1 not in li)#判断是否是在列表中

    print(len(li))#长度

    #元组 tuple

    print(type((1,'-1',True)))

    #int 类型

    print(type((1)))

    #tuple类型

    print(type((1,)))

    #typle类型

    print(type(()))

    #集合

    s1={1,2,3,4,5,6}

    s2={1,2,3,4,5,7,8}

    print(type(s1))

    print(s1-s2)#除去

    print(s1&s2)#共同

    print(s1|s2)#相加

    #字典

    d={'Q':'新月打击','W':'苍白之瀑','E':'月之降临,'R':月神冲刺'}

    print(type({}))#空的字典

    print(d['Q'])#输出新月打击

    相关文章

      网友评论

        本文标题:Python基本数据类型

        本文链接:https://www.haomeiwen.com/subject/zhfbbftx.html