-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayload.json
More file actions
1803 lines (1803 loc) · 74.8 KB
/
Copy pathpayload.json
File metadata and controls
1803 lines (1803 loc) · 74.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"schemaVersion": "1",
"version": "1.0.0",
"graph": {
"slug": "python",
"content": [
{
"locale": "zh-CN",
"name": "Python",
"description": "Python 图谱覆盖 Python 语言核心、标准库、类型标注、模块包、错误处理和常用并发模型。"
},
{
"locale": "en",
"name": "Python",
"description": "The Python graph covers the Python language core, standard library, type hints, modules and packages, error handling, and common concurrency models."
}
]
},
"nodes": [
{
"slug": "python",
"parentSlug": null,
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "Python",
"summary": "Python 是解释型、动态类型、面向对象的高级语言,设计哲学强调代码可读性——「一切皆对象」,语法简洁且跨平台。Python 3 是当前主流版本,与 Python 2 不兼容。",
"detail": null
},
{
"locale": "en",
"title": "Python",
"summary": "Python is an interpreted, dynamically typed, object-oriented language whose design philosophy prioritizes readability—everything is an object and the syntax is clean and cross-platform. Python 3 is the current mainstream version, incompatible with Python 2.",
"detail": null
}
]
},
{
"slug": "data-types",
"parentSlug": "python",
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "数据类型",
"summary": "Python 内置类型覆盖数值、文本、序列、映射与集合,所有类型均为对象,变量只是对象的引用(动态类型)。",
"detail": null
},
{
"locale": "en",
"title": "Data Types",
"summary": "Python's built-in types cover numbers, text, sequences, mappings, and sets; all types are objects and variables are merely references (dynamic typing).",
"detail": null
}
]
},
{
"slug": "int-float-complex",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "数值类型",
"summary": "`int` 任意精度无溢出,`float` 遵循 `IEEE` 754 双精度,`complex` 含实部与虚部。整除用 `//`,幂运算用 **;浮点精度问题(`0.1+0.2≠0.3`)需用 `decimal` 模块。",
"detail": null
},
{
"locale": "en",
"title": "Numeric Types",
"summary": "`int` has arbitrary precision (no overflow), `float` follows `IEEE` 754 double precision, and `complex` holds real + imaginary parts. Use `//` for floor division and ** for exponentiation; handle floating-point precision issues with the `decimal` module.",
"detail": null
}
]
},
{
"slug": "bool",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 1,
"content": [
{
"locale": "zh-CN",
"title": "布尔类型",
"summary": "`bool` 是 `int` 子类,`True==1`,`False==0`;假值(Falsy)包括 `0`、`''`、`[]`、`{}`、`None`。`and`/`or` 短路求值并返回操作数本身,不一定返回 bool。",
"detail": null
},
{
"locale": "en",
"title": "Boolean Type",
"summary": "`bool` is a subclass of `int`; `True==1` and `False==0`. Falsy values include `0`, `''`, `[]`, `{}`, and `None`. `and`/`or` short-circuit and return one of their operands, not necessarily a bool.",
"detail": null
}
]
},
{
"slug": "strings",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 2,
"content": [
{
"locale": "zh-CN",
"title": "字符串",
"summary": "`str` 是不可变 Unicode 字符序列,支持索引、切片和 `len()`。拼接大量字符串应用 `''.join(list)` 而非 `+=`。",
"detail": null
},
{
"locale": "en",
"title": "Strings",
"summary": "`str` is an immutable Unicode character sequence supporting indexing, slicing, and `len()`. Use `''.join(list)` instead of `+=` when concatenating many pieces.",
"detail": null
}
]
},
{
"slug": "f-strings",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 3,
"content": [
{
"locale": "zh-CN",
"title": "f-string",
"summary": "`f-string`(Python 3.6+)是字符串格式化首选方式,花括号内可嵌入任意表达式,支持格式规范 `f'{v:.2f}'` 和转换标志 `f'{x!r}'`。性能优于 `%` 格式化和 `str.format()`。",
"detail": null
},
{
"locale": "en",
"title": "f-strings",
"summary": "`f-strings` (Python 3.6+) are the preferred formatting tool; any expression can appear in braces with format specs (`f'{v:.2f}'`) or conversion flags (`f'{x!r}'`). They outperform `%` formatting and `str.format()`.",
"detail": null
}
]
},
{
"slug": "string-methods",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 4,
"content": [
{
"locale": "zh-CN",
"title": "字符串方法",
"summary": "常用方法:`split()`/`join()`、`strip()`、`upper()`/`lower()`、`replace()`、`startswith()`/`endswith()`、`find()`/`index()`。所有方法返回新字符串,原串不变。",
"detail": null
},
{
"locale": "en",
"title": "String Methods",
"summary": "Key methods: `split()`/`join()`, `strip()`, `upper()`/`lower()`, `replace()`, `startswith()`/`endswith()`, `find()`/`index()`. All return new strings—the original is unchanged.",
"detail": null
}
]
},
{
"slug": "lists",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 5,
"content": [
{
"locale": "zh-CN",
"title": "列表",
"summary": "`list` 是可变有序序列,支持 `append()`、`extend()`、`insert()`、`pop()`、`sort()` 及切片 `lst[a:b:c]`。列表是引用容器,复制嵌套结构需用 `copy.deepcopy()`。",
"detail": null
},
{
"locale": "en",
"title": "Lists",
"summary": "`list` is a mutable ordered sequence with `append()`, `extend()`, `insert()`, `pop()`, `sort()`, and slicing `lst[a:b:c]`. Lists are reference containers; copy nested structures with `copy.deepcopy()`.",
"detail": null
}
]
},
{
"slug": "tuples",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 6,
"content": [
{
"locale": "zh-CN",
"title": "元组",
"summary": "`tuple` 是不可变有序序列,可用作字典键;单元素元组需尾逗号 `(1,)`。函数多返回值本质是元组,可用解包 `a, b = f()` 接收。",
"detail": null
},
{
"locale": "en",
"title": "Tuples",
"summary": "`tuple` is an immutable ordered sequence usable as dict keys; a single-element tuple requires a trailing comma `(1,)`. Multiple return values are tuples, receivable via unpacking `a, b = f()`.",
"detail": null
}
]
},
{
"slug": "dicts",
"parentSlug": "data-types",
"category": "core",
"sortOrder": 7,
"content": [
{
"locale": "zh-CN",
"title": "字典",
"summary": "`dict` 是键值映射(Python 3.7+ 保留插入顺序),键须可哈希。安全取值用 `d.get(key, default)`;遍历用 `.items()`/`.keys()`/`.values()`;字典推导 `{k: v for k, v in ...}`。",
"detail": null
},
{
"locale": "en",
"title": "Dictionaries",
"summary": "`dict` is a key-value mapping preserving insertion order (Python 3.7+); keys must be hashable. Safe access: `d.get(key, default)`; iterate with `.items()`/`.keys()`/`.values()`; create with dict comprehension `{k: v for k, v in ...}`.",
"detail": null
}
]
},
{
"slug": "sets",
"parentSlug": "data-types",
"category": "common",
"sortOrder": 8,
"content": [
{
"locale": "zh-CN",
"title": "集合",
"summary": "`set` 是无序不重复元素集合,支持 `|`(并)、`&`(交)、`-`(差)、`^`(对称差);`frozenset` 为不可变版本。空集合写 `set()`,`{}` 创建空字典。",
"detail": null
},
{
"locale": "en",
"title": "Sets",
"summary": "`set` is an unordered collection of unique elements with `|` (union), `&` (intersection), `-` (difference), and `^` (symmetric difference); `frozenset` is the immutable variant. An empty set must be `set()`—`{}` creates an empty dict.",
"detail": null
}
]
},
{
"slug": "control-flow",
"parentSlug": "python",
"category": "core",
"sortOrder": 1,
"content": [
{
"locale": "zh-CN",
"title": "控制流",
"summary": "Python 用缩进表示代码块,控制流包括条件、循环与推导式,是写出 Pythonic 代码的基础。",
"detail": null
},
{
"locale": "en",
"title": "Control Flow",
"summary": "Python uses indentation for code blocks; control flow includes conditionals, loops, and comprehensions—the foundation of idiomatic Python.",
"detail": null
}
]
},
{
"slug": "conditionals",
"parentSlug": "control-flow",
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "条件语句",
"summary": "`if`/`elif`/`else` 是唯一条件语句;三元表达式 `x if cond else y`。`is` 比较对象身份,`==` 比较值,不要混用。",
"detail": null
},
{
"locale": "en",
"title": "Conditionals",
"summary": "`if`/`elif`/`else` is the only conditional; ternary expression is `x if cond else y`. Use `is` for identity and `==` for value equality—never mix them.",
"detail": null
}
]
},
{
"slug": "for-loops",
"parentSlug": "control-flow",
"category": "core",
"sortOrder": 1,
"content": [
{
"locale": "zh-CN",
"title": "for 循环",
"summary": "`for item in iterable` 遍历任意可迭代对象;配合 `range()`、`enumerate()`、`zip()` 覆盖常见模式。`for...else` 的 `else` 在循环未被 `break` 中断时执行。",
"detail": null
},
{
"locale": "en",
"title": "for Loops",
"summary": "`for item in iterable` iterates over any iterable; combine with `range()`, `enumerate()`, and `zip()` for common patterns. `for...else`: the `else` block runs only when the loop exits without `break`.",
"detail": null
}
]
},
{
"slug": "while-loops",
"parentSlug": "control-flow",
"category": "core",
"sortOrder": 2,
"content": [
{
"locale": "zh-CN",
"title": "while 循环",
"summary": "`while condition:` 适合迭代次数未知的场景;忘记更新循环变量会导致死循环。Python 无 `do-while`,用 `while True: ... if cond: break` 模拟。",
"detail": null
},
{
"locale": "en",
"title": "while Loops",
"summary": "`while condition:` suits unknown-iteration-count scenarios; forgetting to update the loop variable causes infinite loops. Python has no `do-while`—simulate with `while True: ... if cond: break`.",
"detail": null
}
]
},
{
"slug": "break-continue",
"parentSlug": "control-flow",
"category": "core",
"sortOrder": 3,
"content": [
{
"locale": "zh-CN",
"title": "break 与 continue",
"summary": "`break` 退出最近一层循环,`continue` 跳过当前迭代;两者只影响最近层。跳出嵌套循环常将内层提取为函数后 `return`。",
"detail": null
},
{
"locale": "en",
"title": "break & continue",
"summary": "`break` exits the innermost loop; `continue` skips to the next iteration—both affect only the innermost loop. To escape nested loops, extract the inner loop into a function and `return`.",
"detail": null
}
]
},
{
"slug": "comprehensions",
"parentSlug": "control-flow",
"category": "core",
"sortOrder": 4,
"content": [
{
"locale": "zh-CN",
"title": "推导式",
"summary": "列表 `[expr for x in iter if cond]`、字典 `{k:v ...}`、集合 `{expr ...}`、生成器 `(expr ...)` 推导式比等效 `for+append` 更快且可读性更强。嵌套超两层时应改用普通循环。",
"detail": null
},
{
"locale": "en",
"title": "Comprehensions",
"summary": "List `[expr for x in iter if cond]`, dict `{k:v ...}`, set `{expr ...}`, and generator `(expr ...)` comprehensions are faster and more readable than `for`+`append`. Switch to plain loops beyond two levels of nesting.",
"detail": null
}
]
},
{
"slug": "match-statement",
"parentSlug": "control-flow",
"category": "common",
"sortOrder": 5,
"content": [
{
"locale": "zh-CN",
"title": "match 语句",
"summary": "`match`/`case`(Python 3.10+)支持结构化模式匹配:字面量、序列解构、映射、类模式、OR 模式(`|`)和守卫条件(`if`)。比复杂 `if/elif` 链可读性更强。",
"detail": null
},
{
"locale": "en",
"title": "match Statement",
"summary": "`match`/`case` (Python 3.10+) provides structural pattern matching: literal, sequence, mapping, class, OR (`|`) patterns, and guard conditions (`if`). Far more readable than complex `if`/`elif` chains for branching on data shapes.",
"detail": null
}
]
},
{
"slug": "walrus-operator",
"parentSlug": "control-flow",
"category": "rare",
"sortOrder": 6,
"content": [
{
"locale": "zh-CN",
"title": "海象运算符 :=",
"summary": "`:=`(Python 3.8+)赋值表达式,在表达式内赋值并返回该值,典型用法:`while chunk := f.read(8192):`。滥用降低可读性,只在显著减少重复时使用。",
"detail": null
},
{
"locale": "en",
"title": "Walrus Operator :=",
"summary": "`:=` (Python 3.8+) is an assignment expression that assigns and returns a value inline; classic use: `while chunk := f.read(8192):`. Overuse harms readability—apply only when it meaningfully reduces repetition.",
"detail": null
}
]
},
{
"slug": "functions",
"parentSlug": "python",
"category": "core",
"sortOrder": 2,
"content": [
{
"locale": "zh-CN",
"title": "函数",
"summary": "Python 函数是一等对象,可赋值、传递和返回。核心概念涵盖参数类型、闭包与装饰器,是高阶编程的基础。",
"detail": null
},
{
"locale": "en",
"title": "Functions",
"summary": "Python functions are first-class objects—assignable, passable, and returnable. Core topics span parameter kinds, closures, and decorators, underpinning advanced Python.",
"detail": null
}
]
},
{
"slug": "function-definition",
"parentSlug": "functions",
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "函数定义",
"summary": "`def name(params): body`,无 `return` 时返回 `None`。可变默认值陷阱:`def f(lst=[])` 跨调用共享列表,应改用 `None` 加判断。",
"detail": null
},
{
"locale": "en",
"title": "Function Definition",
"summary": "`def name(params): body` returns `None` when no `return` is given. Mutable default trap: `def f(lst=[])` shares the list across calls—use `None` with `if lst is None: lst = []`.",
"detail": null
}
]
},
{
"slug": "parameters",
"parentSlug": "functions",
"category": "core",
"sortOrder": 1,
"content": [
{
"locale": "zh-CN",
"title": "参数类型",
"summary": "五类参数:位置、默认值、`*args`(可变位置)、仅关键字(`*` 后)、`**kwargs`(可变关键字)。Python 3.8+ 增加仅位置参数(`/` 前)。",
"detail": null
},
{
"locale": "en",
"title": "Parameter Types",
"summary": "Five kinds: positional, default-value, `*args` (variadic positional), keyword-only (after bare `*`), and `**kwargs` (variadic keyword). Python 3.8+ adds positional-only parameters (before `/`).",
"detail": null
}
]
},
{
"slug": "args-kwargs",
"parentSlug": "functions",
"category": "core",
"sortOrder": 2,
"content": [
{
"locale": "zh-CN",
"title": "*args 与 **kwargs",
"summary": "`*args` 收集多余位置参数为元组,`**kwargs` 收集多余关键字参数为字典;调用侧 `*seq` 展开序列,`**mapping` 展开字典。是实现函数转发和装饰器的基础。",
"detail": null
},
{
"locale": "en",
"title": "*args and **kwargs",
"summary": "`*args` collects extra positional args into a tuple; `**kwargs` collects extra keyword args into a dict. On the call side, `*seq` unpacks a sequence and `**mapping` unpacks a dict. Essential for function forwarding and decorators.",
"detail": null
}
]
},
{
"slug": "lambda",
"parentSlug": "functions",
"category": "common",
"sortOrder": 3,
"content": [
{
"locale": "zh-CN",
"title": "lambda",
"summary": "`lambda args: expr` 创建单表达式匿名函数,常用于 `sorted()`、`map()`、`filter()` 的 `key` 参数。复杂逻辑应定义具名函数;`PEP` 8 不推荐将 lambda 赋值给变量。",
"detail": null
},
{
"locale": "en",
"title": "lambda",
"summary": "`lambda args: expr` creates a single-expression anonymous function, commonly used as the `key` argument to `sorted()`, `map()`, and `filter()`. Define named functions for complex logic; `PEP` 8 discourages assigning a lambda to a variable.",
"detail": null
}
]
},
{
"slug": "closures",
"parentSlug": "functions",
"category": "common",
"sortOrder": 4,
"content": [
{
"locale": "zh-CN",
"title": "闭包",
"summary": "闭包是引用外层变量(自由变量,存于 `__closure__`)的内层函数,外层返回后变量仍存活。循环中建闭包共享同一循环变量(晚绑定),需用默认参数 `lambda i=i: i` 捕获当前值。",
"detail": null
},
{
"locale": "en",
"title": "Closures",
"summary": "A closure is a nested function referencing free variables from its enclosing scope (stored in `__closure__`), which outlive the outer function. Closures in loops share the same loop variable (late binding)—capture the current value with a default argument: `lambda i=i: i`.",
"detail": null
}
]
},
{
"slug": "decorators",
"parentSlug": "functions",
"category": "common",
"sortOrder": 5,
"content": [
{
"locale": "zh-CN",
"title": "装饰器",
"summary": "装饰器是接受函数并返回函数的高阶函数,`@decorator` 等价于 `func = decorator(func)`,可叠加(从下到上执行)。必须用 `functools.wraps(func)` 保留原函数元信息。",
"detail": null
},
{
"locale": "en",
"title": "Decorators",
"summary": "A decorator is a higher-order function accepting and returning a function; `@decorator` equals `func = decorator(func)` and multiple decorators are applied bottom-up. Always use `functools.wraps(func)` to preserve the original function's metadata.",
"detail": null
}
]
},
{
"slug": "functools",
"parentSlug": "functions",
"category": "common",
"sortOrder": 6,
"content": [
{
"locale": "zh-CN",
"title": "functools 模块",
"summary": "核心工具:`@lru_cache`/`@cache` 缓存纯函数;`partial()` 固定部分参数;`wraps()` 保留装饰器元信息;`reduce()` 折叠序列;`total_ordering` 自动补全比较方法。",
"detail": null
},
{
"locale": "en",
"title": "functools Module",
"summary": "Key tools: `@lru_cache`/`@cache` memoize pure functions; `partial()` pre-fills arguments; `wraps()` preserves decorator metadata; `reduce()` folds a sequence; `total_ordering` auto-generates comparison operators from a minimal set.",
"detail": null
}
]
},
{
"slug": "oop",
"parentSlug": "python",
"category": "core",
"sortOrder": 3,
"content": [
{
"locale": "zh-CN",
"title": "面向对象编程",
"summary": "Python 是纯面向对象语言,一切皆对象。`OOP` 核心:类(模板)、实例、继承、封装、多态(鸭子类型)。",
"detail": null
},
{
"locale": "en",
"title": "Object-Oriented Programming",
"summary": "Python is fully object-oriented—everything is an object. `OOP` core: classes (templates), instances, inheritance, encapsulation, and polymorphism (duck typing).",
"detail": null
}
]
},
{
"slug": "classes",
"parentSlug": "oop",
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "类定义",
"summary": "`class Name:` 定义类,方法第一参数约定为 `self`(实例本身,解释器自动传入)。`__init__` 是初始化方法;`isinstance(obj, cls)` 检测实例类型。",
"detail": null
},
{
"locale": "en",
"title": "Class Definition",
"summary": "`class Name:` defines a class; method first parameters are conventionally named `self` (automatically passed by the interpreter). `__init__` initializes instances; `isinstance(obj, cls)` checks instance type.",
"detail": null
}
]
},
{
"slug": "inheritance",
"parentSlug": "oop",
"category": "core",
"sortOrder": 1,
"content": [
{
"locale": "zh-CN",
"title": "继承",
"summary": "`class Child(Parent):` 子类继承父类所有属性和方法;`super()` 按 `MRO` 顺序代理父类,优于硬编码父类名。`issubclass()` 检测继承关系。",
"detail": null
},
{
"locale": "en",
"title": "Inheritance",
"summary": "`class Child(Parent):` inherits all parent attributes and methods; `super()` delegates to the parent following `MRO` order, preferred over hard-coding the parent name. `issubclass()` checks inheritance.",
"detail": null
}
]
},
{
"slug": "dunder-methods",
"parentSlug": "oop",
"category": "common",
"sortOrder": 2,
"content": [
{
"locale": "zh-CN",
"title": "魔术方法",
"summary": "魔术方法(dunder methods)让自定义类融入语言协议。常用:`__init__`、`__str__`/`__repr__`、`__len__`、`__getitem__`、`__iter__`/`__next__`、`__eq__`、`__enter__`/`__exit__`、`__call__`。",
"detail": null
},
{
"locale": "en",
"title": "Magic Methods",
"summary": "Magic methods (dunder methods) let custom classes participate in Python's language protocols. Common ones: `__init__`, `__str__`/`__repr__`, `__len__`, `__getitem__`, `__iter__`/`__next__`, `__eq__`, `__enter__`/`__exit__`, and `__call__`.",
"detail": null
}
]
},
{
"slug": "classmethods-staticmethods",
"parentSlug": "oop",
"category": "common",
"sortOrder": 3,
"content": [
{
"locale": "zh-CN",
"title": "classmethod 与 staticmethod",
"summary": "`@classmethod` 第一参数为类本身(`cls`),常用于工厂构造函数;`@staticmethod` 无隐式参数,适合工具函数。需访问类用 classmethod,无需类或实例时用 staticmethod。",
"detail": null
},
{
"locale": "en",
"title": "classmethod & staticmethod",
"summary": "`@classmethod` receives the class as `cls`, commonly used for factory constructors; `@staticmethod` takes no implicit parameter, suitable for utility helpers. Use classmethod when you need the class; staticmethod when you need neither.",
"detail": null
}
]
},
{
"slug": "properties",
"parentSlug": "oop",
"category": "common",
"sortOrder": 4,
"content": [
{
"locale": "zh-CN",
"title": "property",
"summary": "`@property` 将方法转为只读属性,配合 `@name.setter`/`@name.deleter` 实现受控读写。Python 风格:先用公开属性,只在需要验证或计算时才引入 property。",
"detail": null
},
{
"locale": "en",
"title": "property",
"summary": "`@property` turns a method into a read-only attribute; pair with `@name.setter`/`@name.deleter` for controlled read/write. Python style: start with plain public attributes and refactor to property only when validation or computation is needed.",
"detail": null
}
]
},
{
"slug": "dataclasses",
"parentSlug": "oop",
"category": "common",
"sortOrder": 5,
"content": [
{
"locale": "zh-CN",
"title": "dataclass",
"summary": "`@dataclass`(Python 3.7+)根据注解字段自动生成 `__init__`、`__repr__`、`__eq__`;`frozen=True` 生成不可变类,`field(default_factory=list)` 处理可变默认值。",
"detail": null
},
{
"locale": "en",
"title": "dataclass",
"summary": "`@dataclass` (Python 3.7+) auto-generates `__init__`, `__repr__`, and `__eq__` from annotated fields; `frozen=True` makes it immutable; `field(default_factory=list)` handles mutable defaults.",
"detail": null
}
]
},
{
"slug": "abstract-classes",
"parentSlug": "oop",
"category": "common",
"sortOrder": 6,
"content": [
{
"locale": "zh-CN",
"title": "抽象类",
"summary": "`abc.ABC` + `@abstractmethod` 定义抽象基类,含抽象方法的类无法实例化,子类必须实现所有抽象方法,适合定义插件接口和策略模式。",
"detail": null
},
{
"locale": "en",
"title": "Abstract Classes",
"summary": "`abc.ABC` + `@abstractmethod` defines abstract base classes; classes with abstract methods cannot be instantiated and subclasses must implement all abstract methods—ideal for plugin interfaces and strategy patterns.",
"detail": null
}
]
},
{
"slug": "multiple-inheritance",
"parentSlug": "oop",
"category": "rare",
"sortOrder": 7,
"content": [
{
"locale": "zh-CN",
"title": "多重继承与 MRO",
"summary": "Python 支持 `class C(A, B):`;`MRO` 由 C3 线性化决定,可用 `C.__mro__` 查看。`super()` 按 `MRO` 调用下一个类,菱形继承中每个类只调用一次。优先用 Mixin 模式。",
"detail": null
},
{
"locale": "en",
"title": "Multiple Inheritance & MRO",
"summary": "Python supports `class C(A, B):`; `MRO` is determined by C3 linearization and visible via `C.__mro__`. `super()` calls the next class in `MRO`, visiting each class exactly once in diamond inheritance. Prefer the Mixin pattern.",
"detail": null
}
]
},
{
"slug": "instance-class-vars",
"parentSlug": "oop",
"category": "core",
"sortOrder": 8,
"content": [
{
"locale": "zh-CN",
"title": "实例变量与类变量",
"summary": "实例变量(`self.x`)属于单个实例;类变量(`Class.x`)所有实例共享。通过实例赋值(`self.x = v`)会创建实例变量遮盖类变量,而非修改类变量。",
"detail": null
},
{
"locale": "en",
"title": "Instance vs. Class Variables",
"summary": "Instance variables (`self.x`) belong to one instance; class variables (`Class.x`) are shared by all instances. Assigning via an instance (`self.x = v`) creates an instance variable that shadows the class variable, not modifies it.",
"detail": null
}
]
},
{
"slug": "modules-packages",
"parentSlug": "python",
"category": "core",
"sortOrder": 4,
"content": [
{
"locale": "zh-CN",
"title": "模块与包",
"summary": "模块是单个 `.py` 文件,包是含 `__init__.py` 的目录(Python 3.3+ 支持无 `__init__.py` 的命名空间包)。模块系统是组织代码和实现复用的核心。",
"detail": null
},
{
"locale": "en",
"title": "Modules & Packages",
"summary": "A module is a single `.py` file; a package is a directory with `__init__.py` (Python 3.3+ supports namespace packages without it). The module system is the core mechanism for organizing and reusing code.",
"detail": null
}
]
},
{
"slug": "import-system",
"parentSlug": "modules-packages",
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "import 机制",
"summary": "`import` 依次搜索 `sys.modules` 缓存、内置模块、`sys.path` 路径;首次导入执行模块顶层代码,再次导入返回缓存。`if __name__ == '__main__':` 区分直接运行与被导入。",
"detail": null
},
{
"locale": "en",
"title": "Import Mechanism",
"summary": "`import` searches `sys.modules` cache, built-in modules, then `sys.path` in order; the first import executes the module's top-level code, subsequent ones return the cache. `if __name__ == '__main__':` distinguishes direct execution from import.",
"detail": null
}
]
},
{
"slug": "standard-import",
"parentSlug": "modules-packages",
"category": "core",
"sortOrder": 1,
"content": [
{
"locale": "zh-CN",
"title": "导入语法",
"summary": "四种形式:`import module`(推荐,保留命名空间)、`from module import name`、`from module import name as alias`、`from module import *`(不推荐,污染命名空间)。`__all__` 控制通配符导出。",
"detail": null
},
{
"locale": "en",
"title": "Import Syntax",
"summary": "Four forms: `import module` (recommended, preserves namespace), `from module import name`, `from module import name as alias`, and `from module import *` (avoid—pollutes namespace). `__all__` controls what `import *` exports.",
"detail": null
}
]
},
{
"slug": "pip",
"parentSlug": "modules-packages",
"category": "core",
"sortOrder": 2,
"content": [
{
"locale": "zh-CN",
"title": "pip 包管理",
"summary": "`pip install package`、`pip install -r requirements.txt`、`pip freeze > requirements.txt`。现代项目推荐配合 `pyproject.toml`,或改用 `uv`、`poetry` 等工具。",
"detail": null
},
{
"locale": "en",
"title": "pip Package Manager",
"summary": "`pip install package`, `pip install -r requirements.txt`, `pip freeze > requirements.txt`. Modern projects favor `pyproject.toml` with pip or tools like `uv` and `poetry`.",
"detail": null
}
]
},
{
"slug": "error-handling",
"parentSlug": "python",
"category": "core",
"sortOrder": 5,
"content": [
{
"locale": "zh-CN",
"title": "错误处理",
"summary": "Python 用异常机制处理错误,所有异常继承 `BaseException`。Python 风格偏向 `EAFP`(先做后道歉):先尝试操作再捕获异常,而非预先检查所有条件。",
"detail": null
},
{
"locale": "en",
"title": "Error Handling",
"summary": "Python uses exceptions for errors; all exceptions inherit from `BaseException`. Python style favors `EAFP` (Easier to Ask Forgiveness than Permission): try the operation and catch exceptions rather than pre-checking conditions.",
"detail": null
}
]
},
{
"slug": "try-except",
"parentSlug": "error-handling",
"category": "core",
"sortOrder": 0,
"content": [
{
"locale": "zh-CN",
"title": "try / except",
"summary": "`try: ... except ExceptionType as e:` 捕获特定异常,`except (TypeError, ValueError)` 捕获多类型。始终捕获具体类型,避免裸 `except:` 或宽泛的 `except Exception:`。",
"detail": null
},
{
"locale": "en",
"title": "try / except",
"summary": "`try: ... except ExceptionType as e:` catches a specific type; `except (TypeError, ValueError)` catches multiple. Always catch specific types—avoid bare `except:` (catches `KeyboardInterrupt`) and overly broad `except Exception:`.",
"detail": null
}
]
},
{
"slug": "raise",
"parentSlug": "error-handling",
"category": "core",
"sortOrder": 1,
"content": [
{
"locale": "zh-CN",
"title": "raise",
"summary": "`raise ExceptionType(msg)` 主动抛出;裸 `raise` 在 `except` 块内重新抛出(保留 traceback)。`raise New from Original` 显式异常链;`raise New from None` 抑制原因。",
"detail": null
},
{
"locale": "en",
"title": "raise",
"summary": "`raise ExceptionType(msg)` raises explicitly; bare `raise` inside `except` re-raises the current exception (preserving traceback). `raise New from Original` creates an explicit exception chain; `raise New from None` suppresses the cause.",
"detail": null
}
]
},
{
"slug": "custom-exceptions",
"parentSlug": "error-handling",
"category": "common",
"sortOrder": 2,
"content": [
{
"locale": "zh-CN",
"title": "自定义异常",
"summary": "继承 `Exception` 定义业务语义异常,按类别构建层次(`AppError -> DatabaseError`)让调用方可精确捕获。自定义 `__init__` 可携带额外上下文。",
"detail": null
},
{
"locale": "en",
"title": "Custom Exceptions",
"summary": "Inherit from `Exception` for domain exceptions; build a hierarchy by category (`AppError -> DatabaseError`) so callers can catch at the right granularity. Add `__init__` to carry extra context.",
"detail": null
}
]
},
{
"slug": "iterators-generators",
"parentSlug": "python",
"category": "common",
"sortOrder": 6,
"content": [
{
"locale": "zh-CN",
"title": "迭代器与生成器",
"summary": "迭代器协议和生成器是 Python 惰性计算的核心,支持处理大型或无限序列而无需加载全部内容到内存。",
"detail": null
},
{
"locale": "en",
"title": "Iterators & Generators",
"summary": "The iterator protocol and generators are the core of Python's lazy evaluation, enabling processing of large or infinite sequences without loading everything into memory.",
"detail": null
}
]
},
{
"slug": "concurrency",
"parentSlug": "python",
"category": "common",
"sortOrder": 7,
"content": [
{
"locale": "zh-CN",
"title": "并发",
"summary": "Python 常见并发模型包括线程、进程、`asyncio` 协作式 I/O,以及较新的子解释器/自由线程方向。选择模型时先判断任务是 I/O 密集、CPU 密集,还是需要大量共享状态。不要把 `async` 当作自动并行;它主要改善高并发 I/O 的调度方式。",
"detail": null
},
{
"locale": "en",
"title": "Concurrency",
"summary": "Python commonly uses threads, processes, cooperative `asyncio` I/O, and newer directions such as subinterpreters and free-threaded builds. Choose the model by deciding whether the work is I/O-bound, CPU-bound, or heavy on shared state. Do not treat `async` as automatic parallelism; it mainly improves scheduling for high-concurrency I/O.",
"detail": null
}
]
},
{
"slug": "stdlib",
"parentSlug": "python",
"category": "common",
"sortOrder": 8,
"content": [
{
"locale": "zh-CN",
"title": "标准库",
"summary": "Python「自带电池」——标准库覆盖文件操作、时间日期、正则、网络、测试等绝大多数常见需求,无需第三方依赖即可完成大量任务。",
"detail": null
},
{
"locale": "en",
"title": "Standard Library",
"summary": "Python is \"batteries included\"—the standard library covers file `I/O`, `date/time`, regex, networking, testing, and most common needs, enabling a huge range of tasks without third-party dependencies.",
"detail": null
}
]
},
{
"slug": "type-hints",
"parentSlug": "python",
"category": "common",
"sortOrder": 9,
"content": [
{
"locale": "zh-CN",
"title": "类型注解",
"summary": "类型注解(Python 3.5+)通过 `: Type` 和 `-> Type` 语法为变量和函数标注类型,配合 `mypy/pyright` 等静态分析工具在运行前发现错误。注解纯为静态分析,运行时不强制检查。",
"detail": null
},
{
"locale": "en",
"title": "Type Hints",
"summary": "Type hints (Python 3.5+) annotate variables and functions with `: Type` and `-> Type`, enabling static analysis tools like `mypy/pyright` to catch errors before runtime. Annotations are for static analysis only—they are not enforced at runtime.",
"detail": null
}
]
},
{