From 2379ce5aad18db7c84e21abd10da2b9633eefe3d Mon Sep 17 00:00:00 2001 From: Xudong Date: Tue, 17 Jul 2018 15:41:30 +0800 Subject: [PATCH] Update 2.2.md directly call method getitem() will receive a NameError we can use x.__getitem__(0) or index grammar x[0] --- 2.2.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2.2.md b/2.2.md index d32813c..e4264a4 100644 --- a/2.2.md +++ b/2.2.md @@ -110,9 +110,9 @@ Python 中的元组(以及多数其它编程语言中的序列)下标都以 >>> def make_rat(n, d): return (n, d) >>> def numer(x): - return getitem(x, 0) + return x.__getitem__(0) >>> def denom(x): - return getitem(x, 1) + return x.__getitem__(1) ``` 用于打印有理数的函数完成了我们对抽象数据结构的实现。 -- GitLab