【问题标题】:What is the difference between "Allocable Resource" and "Container" in Python?Python中的“可分配资源”和“容器”有什么区别?
【发布时间】:2020-05-13 02:21:20
【问题描述】:

我正在研究数据结构。 我已经知道 Python 容器有:List、Tuple、Set 和 Dictionary。

在 Python 测验问题中,有一个问题必须确定以下哪些类是重载给定方法列表的类。

但我不明白 Python 中可分配资源的概念。是指栈、队列、二叉树吗?

所以,我使用 dir() 来挖掘每个类并找出它们是否具有问题中指示的方法。

    """A classs overloads the following methods. Which of the following best describes objects
of this class?

__len__
__contains__
__getitem__
__setitem__

A) Generator
B) Iterator
C) Numeric
D) Allocable resource
E) Container
"""
# A) Generator
"""Is not a class"""
# B) Iterator
"""
dir(iter) = 
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', 
'__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__',
 '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', 
 '__reduce_ex__', '__repr__', '__self__', '__setattr__', 
'__sizeof__', '__str__', '__subclasshook__', '__text_signature__']"""
# C) Numeric
"""dir(25) = 
['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', 
'__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', 
'__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__',
 '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__',
  '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__',
   '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', 
   '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', 
   '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__',
    '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 
    'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']"""
# D) Allocable resource
"""???"""
# E) Container
"""Python's general purpose built-in containers, dict , list , set , and tuple """
"""dir(list) = 
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__',
 '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', 
 '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', 
 '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', 
 '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__'
 , '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 
 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']"""

【问题讨论】:

  • 上下文是什么?您在哪里找到了这些条款?
  • 您可能需要为我们提供更多关于如何定义“可分配资源”的上下文。通常,对于一个进程,它会包括所有可用的内存,并且这些内存可供 python 用作对象。所以容器是可分配的资源......直到你的内存用完。
  • 我不认为“可分配资源”是一个标准术语,至少不是特定于 python 的术语。 container 可以是用于包含 其他对象的任何对象。这确实包括listtuplesetdict,但也包括更多内置和非内置的。如果您有堆栈、队列或二叉树,它们也将被视为容器。
  • 嗨@Klaus D。它来自 Python 测验中的一个问题
  • 我编辑了我的问题,我添加了更多关于我的工作的信息。

标签: python containers theory


【解决方案1】:

正确的答案是 Allocable 资源在 Python 中是一个模棱两可的术语,而 Python 容器是对问题中描述的方法可用的容器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 2014-07-29
    • 2013-12-02
    • 2013-02-05
    • 1970-01-01
    相关资源
    最近更新 更多