python的基本数据类型

python的基本数据类

如何查询Python的数据类型呢? 

 1 执行如下命令:
 2 
 3 name_list = [11,22,33]
 4 print(name_list)
 5 print(type(name_list))
 6 
 7 
 8 执行后的结果:
 9 
10 C:\Users\zht\AppData\Local\Programs\Python\Python35\python.exe D:/python3.5/day1/index.py
11 [11, 22, 33]
12 <class 'list'> (这里就是你的数据类型 列表)
13 
14 Process finished with exit code 0
通过(type(name_list))可以看到你变量的类型。这个例子可以让大家明白,如果要查看其它的数据类型就可以这样操作。

 下面带大家认识一下Python的基本数据类型

一、整数

如: 18、73、84

每一个整数都具备如下功能:

class int(object):
    """
    int(x=0) -> integer
    int(x, base=10) -> integer
    
    Convert a number or string to an integer, or return 0 if no arguments
    are given.  If x is a number, return x.__int__().  For floating point
    numbers, this truncates towards zero.
    
    If x is not a number or if base is given, then x must be a string,
    bytes, or bytearray instance representing an integer literal in the
    given base.  The literal can be preceded by '+' or '-' and be surrounded
    by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
    Base 0 means to interpret the base from the string as an integer literal.
    >>> int('0b100', base=0)
    
       def bit_length(self): 
      """ 返回表示该数字的时占用的最少位数 """
        """
        int.bit_length() -> int
        
        Number of bits necessary to represent self in binary.
       
        >>> bin(37)
        '0b100101'
        >>> (37).bit_length()
        6
        """
        return 0
实例:
>>> bin (37)
'0b100101' (显示了你的37这个整数在二进制中占用的位数)
def conjugate(self, *args, **kwargs): # real signature unknown
        """ 返回该复数的共轭复数 """
        """ Returns self, the complex conjugate of any int. """
        pass
    def __abs__(self):(ABS绝对值)

        """ 返回绝对值 """

        """ x.__abs__() <==> abs(x) """

        pass

    实例:

    >>> age = 19
    >>> age
    19

    >>> age.__abs__()
    19

    def __add__(self, y):(返回相加的数值)

        """ x.__add__(y) <==> x+y """

        pass

    >>> age
    19
    >>> age.__add__(100)
    119

    def __and__(self, y): (AND就是创建方法执行对象得出结果)(AND也是与运算,就是它且它 )

        """ x.__and__(y) <==> x&y """

        pass


同样原理运用到真假中 真true=1 假 false=0可见,只有前后两个运算数都是 1 的时候结果才是1。其效果与“或”相逆,各有不同用途。

        """ 比较两个数大小 """ def __cmp__(self, y):(python2里面有3就没有了)

        """ x.__cmp__(y) <==> cmp(x,y) """

        pass

 

    def __divmod__(self, y):

        """ 相除,得到商和余数组成的元组 """

        """ x.__divmod__(y) <==> divmod(x, y) """

        pass

    实例:

    >>> age
    10
    >>> age.__divmod__(4)
  (2, 2)

def __eq__(self, *args, **kwargs): # real signature unknown
    """ Return self==value. """
    pass
  实例: 

  >>> age
  10
  >>> age.__eq__(10)
  True
  >>> age.__eq__(11)
  False

       def __float__(self):

        """ 转换为浮点类型 """
        """ x.__float__() <==> float(x) """
        pass
  实例:

  >>> age
  10
  >>> age.__float__()
  10.0

def __floordiv__(self, *args, **kwargs): # real signature unknown
""" Return self//value. """(地板除)5//6和5/6不一样。)写WEB的时候可用于分页。)
pass
实例:

  >>> age
  10

  >>> age.__floordiv__(5)

  2
  >>> age.__floordiv__(8)
  1

python
下一个内容

 



  

  

转载于:https://www.cnblogs.com/zhaohongtao/p/6389506.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值