首页 > 编程语言 > 详细

python学习第二天笔记

时间:2020-01-27 12:55:18      阅读:92      评论:0      收藏:0      [点我收藏+]

基本数据类型

一切事物都是对象,对象基于类创建

 技术分享图片

注:查看对象相关成员 var,type,dir

技术分享图片

 

 

一、整数

如: 18、73、84

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

技术分享图片
class int(object):
    """
    int([x]) -> 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)
    4
    """
    def as_integer_ratio(self): # real signature unknown; restored from __doc__
        """
        Return integer ratio.
        
        Return a pair of integers, whose ratio is exactly equal to the original int
        and with a positive denominator.
        
        >>> (10).as_integer_ratio()
        (10, 1)
        >>> (-10).as_integer_ratio()
        (-10, 1)
        >>> (0).as_integer_ratio()
        (0, 1)
        """
        pass

    def bit_length(self): # real signature unknown; restored from __doc__
       """ 返回表示该数字的时占用的最少位数 """
        """
        Number of bits necessary to represent self in binary.
        
        >>> bin(37)
        ‘0b100101‘
        >>> (37).bit_length()
        6
        """
        pass
    def __abs__(self): # real signature unknown; restored from __doc__
       """ 返回表示该数字的绝对值 """
        """ abs(self) """
        """ x.__abs__() <==> abs(x) """
        """
        >>> age = 18
        >>> age.__abs__()
        18
        >>> b = abs(age)
        >>> print(b)
        18
        >>> age = -18
        >>> age
        -18
        >>> age.__abs__()
        18
        >>> b = abs(age)
        >>> print(b)
        18
        """
        pass 

    def __divmod__(self, y): # real signature unknown; restored from __doc__
        """ Return divmod(self, value). """
        """ 相除,得到商和余数组成的元组 """ 
        """ x.__divmod__(y) <==> divmod(x, y) """
        """
        >>> all_item = 95
        >>> pager = 10
        >>> result = all_item.__divmod__(10)
        >>> print(result)
        (9, 5)
        >>> print(divmod(95,10))
        (9, 5)
        """
        pass      
    def __float__(self): # real signature unknown; restored from __doc__
        """ float(self) """
        """ 转换为浮点类型 """ 
        """ x.__float__() <==> float(x) """
        """
        >>> age = 18
        >>> print(type(age))
        <type ‘int‘>
        >>> result = age.__float__()
        >>> print(type(result))
        <type ‘float‘>
        """
        pass          
    def __add__(self, y):
        """ x.__add__(y) <==> x+y """
        """
        >>> age = 18
        >>> result = age.__add__(7)
        >>> print(result)
        25
        >>> b = 18 + 7
        >>> print(b)
        25
        """
        pass                   
    def __floordiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__floordiv__(y) <==> x//y """
        """
        >>> age = 18
        >>> result = age.__floordiv__(5)
        >>> print(result)
        3
        >>> b = 18//5
        >>> print(b)
        3
        """
        pass
int

 

python学习第二天笔记

原文:https://www.cnblogs.com/li-deng/p/12235669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!