一切事物都是对象,对象基于类创建
注:查看对象相关成员 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
原文:https://www.cnblogs.com/li-deng/p/12235669.html