数字分为:

整数(int)

长整型(long)

浮点型(float)

一,整数

整数(int):即不带小数点的数字,如 12 ,45 ,0 ,3

#!/usr/bin/env python

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)
4
"""
def bit_length(self): # real signature unknown; restored from __doc__
"""
''' 返回数字转变为二进制后所站的最小位数,即前面的0不计算在内''' int.bit_length() -> int Number of bits necessary to represent self in binary.
>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
"""
return 0 def conjugate(self, *args, **kwargs): # real signature unknown
""" Returns self, the complex conjugate of any int. """
'''返回复数的共轭负数'''
pass def __abs__(self, *args, **kwargs): # real signature unknown
""" abs(self) """
'''返回值的绝对值 '''
pass def __add__(self, *args, **kwargs): # real signature unknown
""" Return self+value. """
'''两个值相加 '''
pass def __and__(self, *args, **kwargs): # real signature unknown
""" Return self&value. """
'''位运算与(&) '''
pass def __bool__(self, *args, **kwargs): # real signature unknown
""" self != 0 """
'''返回bool值 '''
pass def __ceil__(self, *args, **kwargs): # real signature unknown
""" Ceiling of an Integral returns itself. """
''' '''
pass def __divmod__(self, *args, **kwargs): # real signature unknown
""" Return divmod(self, value). """
'''向除,得到商和余数的元组 '''
pass def __eq__(self, *args, **kwargs): # real signature unknown
""" Return self==value. """
'''相等 '''
pass def __float__(self, *args, **kwargs): # real signature unknown
""" float(self) """
'''转变为浮点型 '''
pass def __floordiv__(self, *args, **kwargs): # real signature unknown
""" Return self//value. """
'''运算符的地板除,得到商余数或小数不显示 '''
pass def __format__(self, *args, **kwargs): # real signature unknown
pass def __getattribute__(self, *args, **kwargs): # real signature unknown
""" Return getattr(self, name). """
pass def __getnewargs__(self, *args, **kwargs): # real signature unknown
'''内部调用 __new__ 方法或创建对象时传入参数使用'''
pass def __ge__(self, *args, **kwargs): # real signature unknown
""" Return self>=value. """
'''大于等于 '''
pass def __gt__(self, *args, **kwargs): # real signature unknown
""" Return self>value. """
'''大于 '''
pass def __hash__(self, *args, **kwargs): # real signature unknown
""" Return hash(self). """
'''如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。在字典中,哈希值用于快速比较字典的键。两个数值相等,则哈希值也相等 '''
pass def __index__(self, *args, **kwargs): # real signature unknown
""" Return self converted to an integer, if self is suitable for use as an index into a list. """
'''用于切片,数字无意义 '''
pass def __init__(self, x, base=10): # known special case of int.__init__
'''构造方法,执行 x = 10 或 x = int(10)时,自动调用'''
"""
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)
4
# (copied from class doc)
"""
pass def __int__(self, *args, **kwargs): # real signature unknown
'''转为整数'''
""" int(self) """
pass def __invert__(self, *args, **kwargs): # real signature unknown
""" ~self """
pass def __le__(self, *args, **kwargs): # real signature unknown
'''小于等于'''
""" Return self<=value. """
pass def __lshift__(self, *args, **kwargs): # real signature unknown
'''位运算符,左移位运算'''
""" Return self<<value. """
pass def __lt__(self, *args, **kwargs): # real signature unknown
'''小于'''
""" Return self<value. """
pass def __mod__(self, *args, **kwargs): # real signature unknown
'''取模,及余数'''
""" Return self%value. """
pass def __mul__(self, *args, **kwargs): # real signature unknown
'''乘'''
""" Return self*value. """
pass def __neg__(self, *args, **kwargs): # real signature unknown
'''正负转换'''
""" -self """
pass @staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
""" Create and return a new object. See help(type) for accurate signature. """
pass def __ne__(self, *args, **kwargs): # real signature unknown
'''不等于'''
""" Return self!=value. """
pass def __or__(self, *args, **kwargs): # real signature unknown
'''位运算‘或’'''
""" Return self|value. """
pass def __pos__(self, *args, **kwargs): # real signature unknown
""" +self """
pass def __pow__(self, *args, **kwargs): # real signature unknown
""" Return pow(self, value, mod). """
pass
##################################
#以下为上面的反向,及左右位置调换#
##################################
def __radd__(self, *args, **kwargs): # real signature unknown """ Return value+self. """
pass def __rand__(self, *args, **kwargs): # real signature unknown
""" Return value&self. """
pass def __rdivmod__(self, *args, **kwargs): # real signature unknown
""" Return divmod(value, self). """
pass def __repr__(self, *args, **kwargs): # real signature unknown
'''转化为解释器可读的形式'''
""" Return repr(self). """
pass def __rfloordiv__(self, *args, **kwargs): # real signature unknown
""" Return value//self. """
pass def __rlshift__(self, *args, **kwargs): # real signature unknown
""" Return value<<self. """
pass def __rmod__(self, *args, **kwargs): # real signature unknown
""" Return value%self. """
pass def __rmul__(self, *args, **kwargs): # real signature unknown
""" Return value*self. """
pass def __ror__(self, *args, **kwargs): # real signature unknown
""" Return value|self. """
pass def __round__(self, *args, **kwargs): # real signature unknown
"""
Rounding an Integral returns itself.
Rounding with an ndigits argument also returns an integer.
"""
pass def __rpow__(self, *args, **kwargs): # real signature unknown
""" Return pow(value, self, mod). """
pass def __rrshift__(self, *args, **kwargs): # real signature unknown
""" Return value>>self. """
pass def __rshift__(self, *args, **kwargs): # real signature unknown
""" Return self>>value. """
pass def __rsub__(self, *args, **kwargs): # real signature unknown
""" Return value-self. """
pass def __rtruediv__(self, *args, **kwargs): # real signature unknown
""" Return value/self. """
pass def __rxor__(self, *args, **kwargs): # real signature unknown
""" Return value^self. """
pass
############################################# def __sizeof__(self, *args, **kwargs): # real signature unknown
'''返回内存大小,以位为单位'''
""" Returns size in memory, in bytes """
pass def __str__(self, *args, **kwargs): # real signature unknown
'''转换为人阅读的形式,如果没有适于人阅读的形式,则返回解释器阅读的形式'''
""" Return str(self). """
pass def __sub__(self, *args, **kwargs): # real signature unknown
'''减'''
""" Return self-value. """
pass def __truediv__(self, *args, **kwargs): # real signature unknown
'''除'''
""" Return self/value. """
pass def __trunc__(self, *args, **kwargs): # real signature unknown
'''返回值,截取为整型的值,在整数中无意义'''
""" Truncating an Integral returns itself. """
pass def __xor__(self, *args, **kwargs): # real signature unknown
""" Return self^value. """
pass denominator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
'''分母 = 1'''
"""the denominator of a rational number in lowest terms""" imag = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
'''虚数'''
"""the imaginary part of a complex number""" numerator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
'''分子 = 数字大小'''
"""the numerator of a rational number in lowest terms""" real = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
'''实数'''
"""the real part of a complex number"""

  示例:

以下示例

a = 50

b = -47

c = 60

####

bit_length()

>>> bin(a)#转化为二进制数(0b二进制标识)
'0b110010'
>>> a.bit_length()
6

####

__abs__()

>>> a.__abs__()
50
>>> b.__abs__()
47

####

__abb__()

>>> a.__add__(b)
3

####

__and__()

>>> a & c
48
>>> a.__and__(c)
48

####

__bool__()

>>> a.__bool__()
True

>>> d = 0

>>> d.__bool__()
False

####

__divmod__()

>>> c.__divmod__(a)
(1, 10)
####
__eq__()
>>> a.__eq__(c)
False
>>> a.__eq__(50)
####
__float__()
>>> a.__float__()
50.0
####
__floordiv__()
>>> a.__floordiv__(4)
12
####
__ge__()
>>> a.__ge__(c)
False
>>> a.__ge__(34)
True
####
__int__()
>>> x = 34.5
>>> x.__int__()
34
####
__lshift__()
>>> a << 2
200
>>> a.__lshift__(2)
####
__mod__()
>>> a.__mod__(3)
2
>>> a % 3
2
####
__mul__()
>>> a * 3
150
>>> a.__mul__(3)
150
####
__neg__()
>>> a.__neg__()
-50
>>> b.__neg__()
47
####



二,长整型

长整型(long):在python 3.X 版本和整数(int)合并了,里面的方法可以通用。

三,浮点型

浮点型(float):即带小数点的数

#!/usr/bin/env python
class float(object):
"""
float(x) -> floating point number Convert a string or number to a floating point number, if possible.
"""
def as_integer_ratio(self): # real signature unknown; restored from __doc__
'''返回值的最简比'''
"""
float.as_integer_ratio() -> (int, int) Return a pair of integers, whose ratio is exactly equal to the original
float and with a positive denominator.
Raise OverflowError on infinities and a ValueError on NaNs. >>> (10.0).as_integer_ratio()
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>> (-.25).as_integer_ratio()
(-1, 4)
"""
pass def conjugate(self, *args, **kwargs): # real signature unknown """ Return self, the complex conjugate of any float. """
pass def fromhex(self, string): # real signature unknown; restored from __doc__
'''将十六进制字符串转化为浮点型'''
"""
float.fromhex(string) -> float Create a floating-point number from a hexadecimal string.
>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324
"""
return 0.0 def hex(self): # real signature unknown; restored from __doc__
'''返回值的十六进制数'''
"""
float.hex() -> string Return a hexadecimal representation of a floating-point number.
>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
"""
return "" def is_integer(self, *args, **kwargs): # real signature unknown
'''判断值是否是整型,如果是返回真'''
""" Return True if the float is an integer. """
pass def __abs__(self, *args, **kwargs): # real signature unknown
""" abs(self) """
pass def __add__(self, *args, **kwargs): # real signature unknown
""" Return self+value. """
pass def __bool__(self, *args, **kwargs): # real signature unknown
""" self != 0 """
pass def __divmod__(self, *args, **kwargs): # real signature unknown
""" Return divmod(self, value). """
pass def __eq__(self, *args, **kwargs): # real signature unknown
""" Return self==value. """
pass def __float__(self, *args, **kwargs): # real signature unknown
""" float(self) """
pass def __floordiv__(self, *args, **kwargs): # real signature unknown
""" Return self//value. """
pass def __format__(self, format_spec): # real signature unknown; restored from __doc__
"""
float.__format__(format_spec) -> string Formats the float according to format_spec.
"""
return "" def __getattribute__(self, *args, **kwargs): # real signature unknown
""" Return getattr(self, name). """
pass def __getformat__(self, typestr): # real signature unknown; restored from __doc__
"""
float.__getformat__(typestr) -> string You probably don't want to use this function. It exists mainly to be
used in Python's test suite. typestr must be 'double' or 'float'. This function returns whichever of
'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the
format of floating point numbers used by the C type named by typestr.
"""
return "" def __getnewargs__(self, *args, **kwargs): # real signature unknown
pass def __ge__(self, *args, **kwargs): # real signature unknown
""" Return self>=value. """
pass def __gt__(self, *args, **kwargs): # real signature unknown
""" Return self>value. """
pass def __hash__(self, *args, **kwargs): # real signature unknown
""" Return hash(self). """
pass def __init__(self, x): # real signature unknown; restored from __doc__
pass def __int__(self, *args, **kwargs): # real signature unknown
""" int(self) """
pass def __le__(self, *args, **kwargs): # real signature unknown
""" Return self<=value. """
pass def __lt__(self, *args, **kwargs): # real signature unknown
""" Return self<value. """
pass def __mod__(self, *args, **kwargs): # real signature unknown
""" Return self%value. """
pass def __mul__(self, *args, **kwargs): # real signature unknown
""" Return self*value. """
pass def __neg__(self, *args, **kwargs): # real signature unknown
""" -self """
pass @staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
""" Create and return a new object. See help(type) for accurate signature. """
pass def __ne__(self, *args, **kwargs): # real signature unknown
""" Return self!=value. """
pass def __pos__(self, *args, **kwargs): # real signature unknown
""" +self """
pass def __pow__(self, *args, **kwargs): # real signature unknown
""" Return pow(self, value, mod). """
pass def __radd__(self, *args, **kwargs): # real signature unknown
""" Return value+self. """
pass def __rdivmod__(self, *args, **kwargs): # real signature unknown
""" Return divmod(value, self). """
pass def __repr__(self, *args, **kwargs): # real signature unknown
""" Return repr(self). """
pass def __rfloordiv__(self, *args, **kwargs): # real signature unknown
""" Return value//self. """
pass def __rmod__(self, *args, **kwargs): # real signature unknown
""" Return value%self. """
pass def __rmul__(self, *args, **kwargs): # real signature unknown
""" Return value*self. """
pass def __round__(self, *args, **kwargs): # real signature unknown
"""
Return the Integral closest to x, rounding half toward even.
When an argument is passed, work like built-in round(x, ndigits).
"""
pass def __rpow__(self, *args, **kwargs): # real signature unknown
""" Return pow(value, self, mod). """
pass def __rsub__(self, *args, **kwargs): # real signature unknown
""" Return value-self. """
pass def __rtruediv__(self, *args, **kwargs): # real signature unknown
""" Return value/self. """
pass def __setformat__(self, typestr, fmt): # real signature unknown; restored from __doc__
"""
float.__setformat__(typestr, fmt) -> None You probably don't want to use this function. It exists mainly to be
used in Python's test suite. typestr must be 'double' or 'float'. fmt must be one of 'unknown',
'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be
one of the latter two if it appears to match the underlying C reality. Override the automatic determination of C-level floating point type.
This affects how floats are converted to and from binary strings.
"""
pass def __str__(self, *args, **kwargs): # real signature unknown
""" Return str(self). """
pass def __sub__(self, *args, **kwargs): # real signature unknown
""" Return self-value. """
pass def __truediv__(self, *args, **kwargs): # real signature unknown
""" Return self/value. """
pass def __trunc__(self, *args, **kwargs): # real signature unknown
""" Return the Integral closest to x between 0 and x. """
pass imag = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""the imaginary part of a complex number""" real = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""the real part of a complex number"""

  浮点型其他方法和整数型的方法一样。

区别的有:

####

as_integer_ratio()

>>> a = 0.5
>>> a.as_integer_ratio()
(1, 2)

####

fromhex()

>>> float.fromhex('0xffff')
65535.0

####

hex()

>>> a = 65.0
>>> a.hex()
'0x1.0400000000000p+6'

####

>>> a = 65.0
>>> a.is_integer()
True
>>> b = 65.01
>>> b.is_integer()
False

####

python基础知识-数字的更多相关文章

  1. Python开发【第二篇】:Python基础知识

    Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...

  2. python 基础知识(一)

    python 基础知识(一) 一.python发展介绍 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本 ...

  3. python 爬虫与数据可视化--python基础知识

    摘要:偶然机会接触到python语音,感觉语法简单.功能强大,刚好朋友分享了一个网课<python 爬虫与数据可视化>,于是在工作与闲暇时间学习起来,并做如下课程笔记整理,整体大概分为4个 ...

  4. python基础知识小结-运维笔记

    接触python已有一段时间了,下面针对python基础知识的使用做一完整梳理:1)避免‘\n’等特殊字符的两种方式: a)利用转义字符‘\’ b)利用原始字符‘r’ print r'c:\now' ...

  5. Python基础知识(五)

    # -*- coding: utf-8 -*-# @Time : 2018-12-25 19:31# @Author : 三斤春药# @Email : zhou_wanchun@qq.com# @Fi ...

  6. Python 基础知识(一)

    1.Python简介 1.1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时 ...

  7. python基础知识部分练习大全

    python基础知识部分练习大全   1.执行 Python 脚本的两种方式 答:1.>>python ../pyhton.py 2. >>python.py   #必须在首行 ...

  8. 开发技术--浅谈python基础知识

    开发|浅谈python基础知识 最近复习一些基础内容,故将Python的基础进行了总结.注意:这篇文章只列出来我觉得重点,并且需要记忆的知识. 前言 目前所有的文章思想格式都是:知识+情感. 知识:对 ...

  9. python基础知识(一)

    Python基础知识 计算基础知识 1.cpu 人类的大脑 运算和处理问题 2.内存 临时存储数据 断电就消失了 3.硬盘 永久存储数据 4.操作系统 调度硬件设备之间数据交互 python的应用和历 ...

随机推荐

  1. C语言序列点问题总结(大多数高等教育C语言教学课程的漏洞)

    C语言序列点总结 2013年11月21于浙大华家池 C 语言副作用: (side effect)是指对数据对象或者文件的修改. 例如,语句 v = 99;的副作用是把 v 的值修改成 99. C语言序 ...

  2. 计算机器内存数量+引入和显示ARDS成员

    [1]README 1.1) 本代码在于读取内存中多个 内存段的地址范围描述符结构体(ARDS),有多少个内存段可以用: 1.2) source code and images in the blog ...

  3. 九度OJ 1060:完数VS盈数 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5590 解决:2093 题目描述: 一个数如果恰好等于它的各因子(该数本身除外)子和,如:6=3+2+1.则称其为"完数" ...

  4. cmake的外部编译

    1 什么是外部编译 就是让源码文件和cmake生成的工程文件分开,将cmake生成的工程文件放在一个单独的目录下面. 2 怎样进行外部编译 第一,单独建立一个目录,这个目录在source code目录 ...

  5. Netty聊天室-源码

    目录 Netty聊天室 源码工程 写在前面 [百万级流量 聊天室实战]: [分布式 聊天室] [Spring +Netty]: [Netty 原理] 死磕 系列 [提升篇]: [内力大增篇]: 疯狂创 ...

  6. mysql系列之3.mysql进阶

    启动原理 mysqld脚本-->mysqld_safe脚本-->mysqld服务-->启动mysql 强制关闭mysql: 三种方法, 不建议用! killall mysqld pk ...

  7. 80端口未被占用,apache无法启动,命令行运行httpd.exe提示文档内容有错

    Apache无法启动,端口被占用的可能性比较大,所以建议大家还是先换端口试试,这个网上说的比较多,具体可参见http://www.cnblogs.com/zdan68/p/3855636.html. ...

  8. 【题解】 P1373 小a和uim之大逃离

    题解 P1373 小a和uim之大逃离 传送门 一道dp好题 乍看此题,感觉要这样设计: \(dp(x)(y)(mod_{a})(mod_{uim})(0/1)\) , 但是我上午考试就MLE了,赶紧 ...

  9. client网络优化方法

    减小图片大小(使用WebP格式的图片)  大部分的Facebook应用数据都是图片,因此降低图片的大小就能够较少数据的下载量.从而加快下载速度,这一点在高延迟的网络环境下很重要.Facebook返回给 ...

  10. WordPress用户角色及其权限管理编辑插件:User Role Editor汉化版

    如果Wordpress默认的用户角色及权限不能满足您的需求,又觉得修改代码编辑用户权限太麻烦.那不妨试试User Role Editor,Wordpress用户角色及其权限管理编辑插件. User R ...