鱼C论坛

 找回密码
 立即注册
查看: 3806|回复: 15

《Fluent Python》书上一段话看不明白求解释

[复制链接]
发表于 2016-8-26 17:36:25 | 显示全部楼层 |阅读模式
20鱼币
本帖最后由 碗碗的泡菜坛 于 2016-8-26 17:35 编辑

本来似乎应该发到英语板块???但是我发现好久都没人点开帖子
那还是发这里好了。。。。

==============一个暴躁的开场================

那个说我英语不好不要看英文原版书的童鞋!!!
我英语不好还看中文版不是这辈子英语都好不起来了吗
英语不好才要逼自己学英语好吗!!

--------------回到正题----------------

Figure 2-1 helps visualize how mutable sequences differ from immutable ones, while also inheriting several methods from them. Note that the built-in concrete sequence types do not actually subclass the Sequence and MutableSequence abstract base classes (ABCs) depicted, but the ABCs are still useful as a formalization of what functionality to expect from a full-featured sequence type.


屏幕快照 2016-08-26 下午5.10.55.png
Figure 2-1. UML class diagram for some classes from collections.abc (superclasses are on the left; inheritance arrows point from subclasses to superclasses; names in italic are abstract classes and abstract methods)

看得云里雾里,每个单词都知道意思,但是连在一起就不知道作者到底要说什么

最佳答案

查看完整内容

这是本好书,希望你能坚持下去 ------------------------------------ ------------------------------------ one of the way of of grouping sequence types is by mutability: Mutable sequences list , bytearray , array.array , collections.deque and memoryview Immutable sequences tuple , str and bytes --------------------------------- 图2-1 主要讲了class collections.abc.Co ...
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-26 17:36:26 | 显示全部楼层
这是本好书,希望你能坚持下去
------------------------------------
------------------------------------
    one of the way of  of grouping sequence types is by mutability:
Mutable sequences
        list ,  bytearray ,  array.array ,  collections.deque and  memoryview
Immutable sequences
        tuple ,  str and  bytes
---------------------------------
图2-1 主要讲了class collections.abc.Container, class collections.abc.Sized , 和class collections.abc.Iterable  三个抽象类他们是collections.abc 模块下五个抽象类之三,他们是最顶层的抽象类。而class collections.abc.Sequence 继承于Sized, Iterable, Container。MutableSequence 继承于Sequence。当然还有Abstract Methods  和  Mixin Methods 。(可见附图一)

----------------------********************------------------------
也就是说那幅图只是能说明inheriting several methods from them),而至于 visualize how mutable sequences differ from immutable ones你就当它扯淡。真正能说明如何区分可变序列和不可变序列的方法,请继续向下阅读。。。

---------------------------------------------------------------------

Immutable sequences
        An object of an immutable sequence type cannot change once it is created. (If the object contains references to other objects, these other objects may be mutable and may be changed; however, the collection of objects directly referenced by an immutable object cannot change.)

        The following types are immutable sequences:

        Strings
        A string is a sequence of values that represent Unicode code points. All the code points in the range U+0000 - U+10FFFF can be represented in a string. Python doesn’t have a char type; instead, every code point in the string is represented as a string object with length 1. The built-in function ord() converts a code point from its string form to an integer in the range 0 - 10FFFF; chr() converts an integer in the range 0 - 10FFFF to the corresponding length 1 string object. str.encode() can be used to convert a str to bytes using the given text encoding, and bytes.decode() can be used to achieve the opposite.

        Tuples
        The items of a tuple are arbitrary Python objects. Tuples of two or more items are formed by comma-separated lists of expressions. A tuple of one item (a ‘singleton’) can be formed by affixing a comma to an expression (an expression by itself does not create a tuple, since parentheses must be usable for grouping of expressions). An empty tuple can be formed by an empty pair of parentheses.

        Bytes
        A bytes object is an immutable array. The items are 8-bit bytes, represented by integers in the range 0 <= x < 256. Bytes literals (like b'abc') and the built-in function bytes() can be used to construct bytes objects. Also, bytes objects can be decoded to strings via the decode() method.

Mutable sequences
        Mutable sequences can be changed after they are created. The subscription and slicing notations can be used as the target of assignment and del (delete) statements.

        There are currently two intrinsic mutable sequence types:

        Lists
        The items of a list are arbitrary Python objects. Lists are formed by placing a comma-separated list of expressions in square brackets. (Note that there are no special cases needed to form lists of length 0 or 1.)

        Byte Arrays
        A bytearray object is a mutable array. They are created by the built-in bytearray() constructor. Aside from being mutable (and hence unhashable), byte arrays otherwise provide the same interface and functionality as immutable bytes objects.

#### 来自python 3.5.3 documentation

                                                                                                                                                                                                    16.9.4
[[3)}SA]9FK{SO0I@_UP.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-26 18:06:39 | 显示全部楼层
光看这段,也看不出什么来~
只是说 可变序列 和 不可变序列 之间的区别,在于他们继承的方法不一样。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-26 18:26:19 | 显示全部楼层
不用太纠结很清楚的含义, 大概知道就行了
从实现的角度讲解 可变序列 和 不可变序列 之间的区别
UML 图最右边那一块就是可变序列(列表)比不可变序列(元组)多出来的魔术方法
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-29 19:34:13 | 显示全部楼层
本帖最后由 百日维新 于 2016-8-30 00:38 编辑

图 2 - 1 的帮助形象化表达可变序列与不可变序列的不同,然而也从他们继承几个方法。
注意,内置的具体序列类型实际上不是序列和可变序列描述抽象基类描述的子类,但抽象基类仍然是扩展为全功能的序列类型函数有用的形式。
图 2 - 1 UML 类用图解法表示了 abc 集合中的某些类。(左边是父类;继承箭头是从子类指向父类,斜体名是抽象类和抽象方法)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-29 19:35:25 | 显示全部楼层
为什么一个子类会有多个父类
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-8-30 12:04:06 | 显示全部楼层
hldh214 发表于 2016-8-26 18:26
不用太纠结很清楚的含义, 大概知道就行了
从实现的角度讲解 可变序列 和 不可变序列 之间的区别
UML 图最 ...


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-30 13:37:31 | 显示全部楼层
我脚得吧~ 与其在此纠结英文长句的翻译,还不如直接去翻python手册。

ABCs
https://docs.python.org/3/glossary.html#term-abstract-base-class

Built-in   sequence-types
https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range

Collections Abstract Base Classes
https://docs.python.org/3/library/collections.abc.html

看看他们的描述,自然就明白了~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-9-1 22:20:05 | 显示全部楼层

你原来回复的呢???
我最近太忙都没时间学习,都没来得及仔细看你们回复哎!!!
过分啊!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-9-2 10:04:33 | 显示全部楼层
碗碗的泡菜坛 发表于 2016-9-1 22:20
你原来回复的呢???
我最近太忙都没时间学习,都没来得及仔细看你们回复哎!!!
过分啊! ...

难道是他自己删的?
太过份了,分手~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-9-2 10:37:06 | 显示全部楼层
这是什么书?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-9-2 10:44:01 | 显示全部楼层
SixPy 发表于 2016-9-2 10:04
难道是他自己删的?
太过份了,分手~

估计是他删的。。。
黑人问号脸
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-9-2 11:08:21 | 显示全部楼层

标题有写啊
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-9-2 11:41:49 | 显示全部楼层
SixPy 发表于 2016-8-30 13:37
我脚得吧~ 与其在此纠结英文长句的翻译,还不如直接去翻python手册。

ABCs

有道理!!!我去看了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-9-4 20:56:55 | 显示全部楼层
Looker 发表于 2016-9-4 17:13
这是本好书,希望你能坚持下去
------------------------------------
-------------------------------- ...

抽象类我都还没有概念
这本书继续看下去越发觉得写的特别棒一定坚持
这个答案是至今最有诚意答案啦。。。鱼币拿走
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-22 10:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表