@@ -640,6 +640,24 @@ msgid ""
640640">>> v\n"
641641"([1, 2, 3], [3, 2, 1])"
642642msgstr ""
643+ ">>> t = 12345, 54321, 'hello!'\n"
644+ ">>> t[0]\n"
645+ "12345\n"
646+ ">>> t\n"
647+ "(12345, 54321, 'hello!')\n"
648+ ">>> # 元组可以嵌套:\n"
649+ ">>> u = t, (1, 2, 3, 4, 5)\n"
650+ ">>> u\n"
651+ "((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))\n"
652+ ">>> # 元组是不可变对象:\n"
653+ ">>> t[0] = 88888\n"
654+ "Traceback (most recent call last):\n"
655+ " File \" <stdin>\" , line 1, in <module>\n"
656+ "TypeError: 'tuple' object does not support item assignment\n"
657+ ">>> # 但它们可以包含可变对象:\n"
658+ ">>> v = ([1, 2, 3], [3, 2, 1])\n"
659+ ">>> v\n"
660+ "([1, 2, 3], [3, 2, 1])"
643661
644662#: ../../tutorial/datastructures.rst:400
645663msgid ""
@@ -689,6 +707,14 @@ msgid ""
689707">>> singleton\n"
690708"('hello',)"
691709msgstr ""
710+ ">>> empty = ()\n"
711+ ">>> singleton = 'hello', # <-- 注意末尾的逗号\n"
712+ ">>> len(empty)\n"
713+ "0\n"
714+ ">>> len(singleton)\n"
715+ "1\n"
716+ ">>> singleton\n"
717+ "('hello',)"
692718
693719#: ../../tutorial/datastructures.rst:430
694720msgid ""
@@ -701,7 +727,7 @@ msgstr ""
701727
702728#: ../../tutorial/datastructures.rst:434
703729msgid ">>> x, y, z = t"
704- msgstr ""
730+ msgstr ">>> x, y, z = t "
705731
706732#: ../../tutorial/datastructures.rst:436
707733msgid ""
@@ -781,6 +807,9 @@ msgid ""
781807">>> a\n"
782808"{'r', 'd'}"
783809msgstr ""
810+ ">>> a = {x for x in 'abracadabra' if x not in 'abc'}\n"
811+ ">>> a\n"
812+ "{'r', 'd'}"
784813
785814#: ../../tutorial/datastructures.rst:493
786815msgid "Dictionaries"
@@ -863,6 +892,24 @@ msgid ""
863892">>> 'jack' not in tel\n"
864893"False"
865894msgstr ""
895+ ">>> tel = {'jack': 4098, 'sape': 4139}\n"
896+ ">>> tel['guido'] = 4127\n"
897+ ">>> tel\n"
898+ "{'jack': 4098, 'sape': 4139, 'guido': 4127}\n"
899+ ">>> tel['jack']\n"
900+ "4098\n"
901+ ">>> del tel['sape']\n"
902+ ">>> tel['irv'] = 4127\n"
903+ ">>> tel\n"
904+ "{'jack': 4098, 'guido': 4127, 'irv': 4127}\n"
905+ ">>> list(tel)\n"
906+ "['jack', 'guido', 'irv']\n"
907+ ">>> sorted(tel)\n"
908+ "['guido', 'irv', 'jack']\n"
909+ ">>> 'guido' in tel\n"
910+ "True\n"
911+ ">>> 'jack' not in tel\n"
912+ "False"
866913
867914#: ../../tutorial/datastructures.rst:544
868915msgid ""
@@ -875,6 +922,8 @@ msgid ""
875922">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n"
876923"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
877924msgstr ""
925+ ">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n"
926+ "{'sape': 4139, 'guido': 4127, 'jack': 4098}"
878927
879928#: ../../tutorial/datastructures.rst:550
880929msgid ""
@@ -887,6 +936,8 @@ msgid ""
887936">>> {x: x**2 for x in (2, 4, 6)}\n"
888937"{2: 4, 4: 16, 6: 36}"
889938msgstr ""
939+ ">>> {x: x**2 for x in (2, 4, 6)}\n"
940+ "{2: 4, 4: 16, 6: 36}"
890941
891942#: ../../tutorial/datastructures.rst:556
892943msgid ""
@@ -899,6 +950,8 @@ msgid ""
899950">>> dict(sape=4139, guido=4127, jack=4098)\n"
900951"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
901952msgstr ""
953+ ">>> dict(sape=4139, guido=4127, jack=4098)\n"
954+ "{'sape': 4139, 'guido': 4127, 'jack': 4098}"
902955
903956#: ../../tutorial/datastructures.rst:566
904957msgid "Looping Techniques"
@@ -919,6 +972,12 @@ msgid ""
919972"gallahad the pure\n"
920973"robin the brave"
921974msgstr ""
975+ ">>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}\n"
976+ ">>> for k, v in knights.items():\n"
977+ "... print(k, v)\n"
978+ "...\n"
979+ "gallahad the pure\n"
980+ "robin the brave"
922981
923982#: ../../tutorial/datastructures.rst:578
924983msgid ""
@@ -935,6 +994,12 @@ msgid ""
935994"1 tac\n"
936995"2 toe"
937996msgstr ""
997+ ">>> for i, v in enumerate(['tic', 'tac', 'toe']):\n"
998+ "... print(i, v)\n"
999+ "...\n"
1000+ "0 tic\n"
1001+ "1 tac\n"
1002+ "2 toe"
9381003
9391004#: ../../tutorial/datastructures.rst:588
9401005msgid ""
0 commit comments