zoukankan      html  css  js  c++  java
  • python数据类型

    1.python常见的数据类型:

    数字:整型、长整型、浮点数、复数、科学计数法
    字符串:字节字符串、unicode字符串
    List(列表)
    Tuple(元组)

    Dictionary(字典)
    bool(布尔)

    >>> a =1

    >>> b =2L

    >>> c=1.2

    >>> d=1+1j

    >>> e="s"

    >>> f=u"f"

    >>> g=[]

    >>> h=(1,)

    >>> i={1:2}

    >>> True

    True

    >>> type(a)

    <type 'int'>

    >>> type(b)

    <type 'long'>

    >>> type(c)

    <type 'float'>

    >>> type(d)

    <type 'complex'>

    >>> type(e)

    <type 'str'>

    >>> type(f)

    <type 'unicode'>

    >>> type(g)

    <type 'list'>

    >>> type(h)

    <type 'tuple'>

    >>> type(i)

    <type 'dict'>

    >>> type(True)

    <type 'bool'>

    1.2. 判断数据类型:

    >>> isinstance(1,(int,long,str))

    True

    >>> isinstance(1,int)

    True

    >>> type(open("e:\a.txt"))

    <type 'file'>  #文件类型

    >>> def sum():pass

    ...

    >>> type(sum)

    <type 'function'>

    >>> 1e10  #科学计数法

    10000000000.0

    >>> 1e-3

    0.001

    >>> 1e2+100

    200.0

    >>> True

    True

    >>> False

    False

    1.3. 判断是否是字符串:

    #-*- coding: UTF-8 -*-

    s = "hello normal string"

    u=u"unicode"

    if isinstance( s, basestring ):

        print u"是字符串"

    if isinstance( u, basestring ):

        print u"是字符串"

     >>> isinstance(u"s",str)

    False

    >>> isinstance(u"s",unicode)

    True

    >>> isinstance(u"s",basestring)

    True

    >>> isinstance("s",str)

    True

    >>> isinstance("s",unicode)

    False

    >>> isinstance("s",basestring)

    True

  • 相关阅读:
    电脑性能提升三
    电脑实用小技巧
    自定义windows开机声音
    电脑性能提升一
    rpm和yum软件管理
    Linux网络技术管理及进程管理
    RAID磁盘阵列及CentOS7系统启动流程
    Linux磁盘管理及LVM讲解
    Linux计划任务及压缩归档
    Android Studio 常用快捷键及常用设置
  • 原文地址:https://www.cnblogs.com/reyinever/p/7900723.html
Copyright © 2011-2022 走看看