课程笔记_零基础入门学习Python_005_闲聊之Python的数据类型

闲聊之Python的数据类型

  • Python是有数据类型的

    '520’与520的区别,字符串和整型

  • 整型

    Python 整型和长整型没有区别,整数长度不受限制

  • 浮点型

    e计数方法

    >>> a=0.0000001
    >>> a
    1e-07
    
    >>> 15e10
    150000000000.0
    
  • 布尔类型

    布尔类型就是整型0,1;但最好不进行运算

    >>> True + True
    2
    
  • 数据类型的转换

    ## 转换成整型
    >>> a = '520'
    >>> b = int (a) #字符串转整型
    >>> b
    520
    
    >>> a = 5.99
    >>> b = int(a) #浮点转整型
    >>> b
    5
    
    ## 转换成浮点型
    float(a)
    
    ## 转换成字符串
    str(a)
    
  • python的特别之处

    str是内置函数,是关键字,一旦作为变量名,函数名就被替代了;

    >>> str = 'i love you'
    >>> c = str(5e19)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'str' object is not callable
    
  • 确定数据的类型

    ## 利用type
    >>> a= '520'
    >>> type(a)
    <class 'str'>
    
    ## 利用isinstance
    >>> a= '520'
    >>> isinstance(a,str)
    True
    

猜你喜欢

转载自blog.csdn.net/weixin_41754258/article/details/113921841