【问题标题】:python3, in help(int) text, what is the Data descriptors described?python3,在帮助(int)文本中,描述的数据描述符是什么?
【发布时间】:2018-09-13 23:01:22
【问题描述】:

当您使用 help(int) 获取 int 类型的帮助字符串时。最后一部分是:

| ----------------------------------------------------------------------
|  Data descriptors defined here:
|  
|  denominator
|      the denominator of a rational number in lowest terms
|  
|  imag
|      the imaginary part of a complex number
|  
|  numerator
|      the numerator of a rational number in lowest terms
|  
|  real
|      the real part of a complex number

所以这些是复杂类型和分数类的属性,那么为什么在此处列出与整数相关的它们。是某种类型的全局数据描述符吗?

【问题讨论】:

    标签: python int code-documentation


    【解决方案1】:

    complexfractions.Fraction 具有具有这些名称和含义的属性这一事实并不意味着 int 也没有此类属性。不同的类可以随意拥有相似的属性:

    >>> (5).denominator
    1
    >>> (5).imag
    0
    >>> (5).numerator
    5
    >>> (5).real
    5
    

    它们不是某种通用属性或任何东西。 int 类型只是实现了这些属性的描述符,以实现与其他数字类型的互操作性。具体来说,它们是implemented 以符合PEP 3141

    【讨论】:

      猜你喜欢
      • 2011-11-22
      • 2017-04-13
      • 2015-06-08
      • 2020-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 2013-03-20
      相关资源
      最近更新 更多