-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpython_data_types_dashboard.html
More file actions
1687 lines (1571 loc) · 79.6 KB
/
Copy pathpython_data_types_dashboard.html
File metadata and controls
1687 lines (1571 loc) · 79.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Data Types — Interactive Dashboard</title>
<style>
/* ========== Reset & Base ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg-deep: #0f172a;
--bg-panel: #1e293b;
--bg-card: #f8fafc;
--bg-card-alt: #f1f5f9;
--ink: #0f172a;
--ink-soft: #475569;
--ink-mute: #64748b;
--line: #cbd5e1;
--accent: #14b8a6;
--accent-2: #6366f1;
--accent-3: #f59e0b;
--accent-4: #ef4444;
--accent-5: #ec4899;
--code-bg: #0b1220;
--code-fg: #e2e8f0;
--code-key: #c084fc;
--code-str: #86efac;
--code-num: #fbbf24;
--code-com: #64748b;
--code-builtin: #60a5fa;
--code-method: #f472b6;
--code-op: #94a3b8;
--shadow: 0 10px 30px rgba(0,0,0,0.25);
--radius: 14px;
}
html { scroll-behavior: smooth; scroll-padding-top: 90px; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background: var(--bg-deep);
color: var(--bg-card);
line-height: 1.6;
font-size: 16px;
min-height: 100vh;
}
/* ========== Header & Nav ========== */
header.topbar {
position: sticky;
top: 0;
z-index: 100;
background: rgba(15, 23, 42, 0.92);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}
.topbar-inner {
max-width: 1400px;
margin: 0 auto;
padding: 14px 24px;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 38px; height: 38px;
border-radius: 10px;
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
display: grid; place-items: center;
font-weight: 800;
color: white;
font-size: 18px;
box-shadow: 0 4px 14px rgba(20, 184, 166, 0.4);
}
.brand-text h1 {
font-size: 18px;
font-weight: 700;
letter-spacing: 0.3px;
color: #f1f5f9;
}
.brand-text p {
font-size: 12px;
color: #94a3b8;
letter-spacing: 0.4px;
}
nav.main-nav {
display: flex;
gap: 4px;
flex-wrap: wrap;
}
nav.main-nav a {
color: #cbd5e1;
text-decoration: none;
font-size: 13px;
font-weight: 500;
padding: 8px 14px;
border-radius: 8px;
transition: all 0.25s ease;
border: 1px solid transparent;
}
nav.main-nav a:hover {
background: rgba(20, 184, 166, 0.12);
color: #5eead4;
border-color: rgba(20, 184, 166, 0.25);
}
/* ========== Layout ========== */
main {
max-width: 1400px;
margin: 0 auto;
padding: 32px 24px 80px;
}
section.anchor {
scroll-margin-top: 90px;
}
.section-title {
font-size: 13px;
font-weight: 700;
letter-spacing: 2px;
text-transform: uppercase;
color: var(--accent);
margin-bottom: 6px;
}
.section-head h2 {
font-size: 32px;
font-weight: 800;
color: #f8fafc;
margin-bottom: 8px;
letter-spacing: -0.5px;
}
.section-head p {
font-size: 15px;
color: #94a3b8;
max-width: 720px;
margin-bottom: 28px;
}
/* ========== Big Picture Tree ========== */
.tree-wrap {
background: linear-gradient(160deg, #1e293b 0%, #0f172a 100%);
border: 1px solid rgba(148, 163, 184, 0.15);
border-radius: var(--radius);
padding: 40px 28px;
box-shadow: var(--shadow);
overflow-x: auto;
}
.tree {
display: flex;
flex-direction: column;
align-items: center;
min-width: 760px;
position: relative;
}
.node {
border-radius: 12px;
padding: 14px 22px;
font-weight: 700;
text-align: center;
cursor: pointer;
transition: all 0.3s cubic-bezier(.4,0,.2,1);
position: relative;
user-select: none;
border: 2px solid transparent;
font-size: 15px;
letter-spacing: 0.3px;
}
.node:hover {
transform: translateY(-3px);
box-shadow: 0 12px 28px rgba(0,0,0,0.45);
}
.node.root {
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
color: white;
font-size: 18px;
padding: 18px 32px;
box-shadow: 0 8px 24px rgba(20, 184, 166, 0.35);
}
.node.pillar {
color: white;
font-size: 15px;
padding: 14px 24px;
}
.node.pillar.none { background: linear-gradient(135deg, #64748b, #475569); }
.node.pillar.single { background: linear-gradient(135deg, #f59e0b, #d97706); }
.node.pillar.multiple { background: linear-gradient(135deg, #ec4899, #be185d); }
.node.leaf {
background: rgba(30, 41, 59, 0.8);
border: 2px solid;
color: #e2e8f0;
font-size: 13px;
padding: 10px 16px;
font-weight: 600;
}
.node.leaf.none-type { border-color: #64748b; color: #cbd5e1; }
.node.leaf.int, .node.leaf.float, .node.leaf.complex, .node.leaf.bool { border-color: #f59e0b; color: #fbbf24; }
.node.leaf.str, .node.leaf.list, .node.leaf.tuple, .node.leaf.set, .node.leaf.dict { border-color: #ec4899; color: #f9a8d4; }
.node.leaf:hover { background: rgba(51, 65, 85, 1); }
/* Tree connectors */
.tier {
display: flex;
justify-content: center;
gap: 60px;
position: relative;
margin-top: 36px;
flex-wrap: nowrap;
}
.tier::before {
content: "";
position: absolute;
top: -36px;
left: 50%;
width: 2px;
height: 36px;
background: rgba(148, 163, 184, 0.4);
transform: translateX(-50%);
}
.tier.single-row { gap: 40px; }
.pillar-block {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.pillar-block::before {
content: "";
position: absolute;
top: -36px;
left: 50%;
width: 2px;
height: 36px;
background: rgba(148, 163, 184, 0.4);
transform: translateX(-50%);
}
.leaf-group {
display: flex;
flex-direction: column;
gap: 10px;
margin-top: 28px;
position: relative;
align-items: center;
}
.leaf-group::before {
content: "";
position: absolute;
top: -28px;
left: 50%;
width: 2px;
height: 28px;
background: rgba(148, 163, 184, 0.4);
transform: translateX(-50%);
}
.connector-bus {
position: absolute;
top: -36px;
left: 0;
right: 0;
height: 2px;
background: rgba(148, 163, 184, 0.4);
}
.pillar-block:first-child .connector-bus,
.leaf-group-wrapper:first-child .connector-bus { display: none; }
.legend {
display: flex;
gap: 22px;
margin-top: 32px;
flex-wrap: wrap;
justify-content: center;
font-size: 12px;
color: #94a3b8;
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; }
/* ========== Functions vs Methods Strip ========== */
.fvm-strip {
margin-top: 48px;
background: var(--bg-card);
border-radius: var(--radius);
padding: 28px;
box-shadow: var(--shadow);
color: var(--ink);
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
}
.fvm-card {
border-radius: 12px;
padding: 22px;
border: 1px solid var(--line);
}
.fvm-card.fn { background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%); border-color: #6ee7b7; }
.fvm-card.mt { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); border-color: #93c5fd; }
.fvm-card h3 {
font-size: 18px;
font-weight: 800;
margin-bottom: 8px;
display: flex; align-items: center; gap: 10px;
}
.fvm-card.fn h3 { color: #047857; }
.fvm-card.mt h3 { color: #1d4ed8; }
.fvm-card .badge {
font-size: 11px;
padding: 3px 10px;
border-radius: 999px;
font-weight: 700;
letter-spacing: 0.5px;
}
.fvm-card.fn .badge { background: #047857; color: white; }
.fvm-card.mt .badge { background: #1d4ed8; color: white; }
.fvm-card p { font-size: 14px; color: var(--ink-soft); margin: 10px 0 12px; }
.fvm-card .signature {
font-family: "SF Mono", Menlo, Consolas, monospace;
background: var(--code-bg);
color: var(--code-fg);
padding: 10px 14px;
border-radius: 8px;
font-size: 13px;
display: block;
margin-bottom: 8px;
}
.fvm-card .signature .k { color: var(--code-key); }
.fvm-card .signature .b { color: var(--code-builtin); }
.fvm-card .signature .s { color: var(--code-str); }
.fvm-card .signature .m { color: var(--code-method); }
.fvm-card .signature .n { color: var(--code-num); }
@media (max-width: 760px) {
.fvm-strip { grid-template-columns: 1fr; }
}
/* ========== Type Cards ========== */
.pillar-section {
margin-top: 56px;
}
.pillar-banner {
padding: 22px 28px;
border-radius: var(--radius);
color: white;
margin-bottom: 28px;
display: flex;
align-items: center;
gap: 18px;
box-shadow: var(--shadow);
}
.pillar-banner.none { background: linear-gradient(120deg, #475569, #334155); }
.pillar-banner.single { background: linear-gradient(120deg, #f59e0b, #d97706); }
.pillar-banner.multiple { background: linear-gradient(120deg, #ec4899, #be185d); }
.pillar-banner .pb-num {
font-size: 32px;
font-weight: 800;
opacity: 0.5;
letter-spacing: 1px;
}
.pillar-banner h3 {
font-size: 22px;
font-weight: 800;
letter-spacing: 0.3px;
}
.pillar-banner p { font-size: 13px; opacity: 0.85; }
.type-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
gap: 22px;
}
.type-card {
background: var(--bg-card);
color: var(--ink);
border-radius: var(--radius);
overflow: hidden;
box-shadow: var(--shadow);
border-top: 5px solid var(--accent);
display: flex;
flex-direction: column;
transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.type-card:hover {
transform: translateY(-4px);
box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}
.type-card.none { border-top-color: #64748b; }
.type-card.int { border-top-color: #f59e0b; }
.type-card.float { border-top-color: #f59e0b; }
.type-card.complex { border-top-color: #f59e0b; }
.type-card.bool { border-top-color: #f59e0b; }
.type-card.str { border-top-color: #ec4899; }
.type-card.list { border-top-color: #ec4899; }
.type-card.tuple { border-top-color: #ec4899; }
.type-card.set { border-top-color: #ec4899; }
.type-card.dict { border-top-color: #ec4899; }
.card-head {
padding: 18px 22px 14px;
border-bottom: 1px solid var(--line);
background: var(--bg-card-alt);
}
.card-head .type-name {
display: flex;
align-items: baseline;
gap: 12px;
margin-bottom: 6px;
}
.card-head .py-name {
font-family: "SF Mono", Menlo, Consolas, monospace;
font-size: 22px;
font-weight: 800;
color: var(--ink);
}
.card-head .label {
font-size: 13px;
color: var(--ink-mute);
font-weight: 600;
letter-spacing: 0.3px;
}
.card-head .mut-tag {
display: inline-block;
font-size: 10px;
font-weight: 700;
padding: 3px 8px;
border-radius: 6px;
letter-spacing: 0.6px;
text-transform: uppercase;
}
.card-head .mut-tag.mut { background: #fee2e2; color: #b91c1c; }
.card-head .mut-tag.imm { background: #dcfce7; color: #166534; }
.card-head .core {
font-size: 14px;
color: var(--ink-soft);
margin-top: 8px;
line-height: 1.55;
}
.card-head .core strong { color: var(--ink); }
.card-body {
padding: 18px 22px;
flex: 1;
}
.card-body h4 {
font-size: 11px;
font-weight: 700;
letter-spacing: 1.5px;
text-transform: uppercase;
color: var(--ink-mute);
margin: 4px 0 10px;
display: flex;
align-items: center;
gap: 8px;
}
.card-body h4::before {
content: "";
width: 4px; height: 4px;
background: var(--accent);
border-radius: 50%;
}
.card-body h4:not(:first-child) { margin-top: 18px; }
/* Code blocks */
pre.code {
background: var(--code-bg);
border-radius: 8px;
padding: 12px 14px;
overflow-x: auto;
margin-bottom: 8px;
border: 1px solid rgba(148, 163, 184, 0.12);
font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
font-size: 12.5px;
line-height: 1.65;
color: var(--code-fg);
}
pre code { font-family: inherit; background: none; }
.tok-k { color: var(--code-key); font-weight: 600; }
.tok-b { color: var(--code-builtin); }
.tok-s { color: var(--code-str); }
.tok-n { color: var(--code-num); }
.tok-c { color: var(--code-com); font-style: italic; }
.tok-m { color: var(--code-method); }
.tok-o { color: var(--code-op); }
.tok-out { color: #94a3b8; font-style: italic; }
.tok-self { color: var(--code-key); font-style: italic; }
/* Tables */
table.fn-mt {
width: 100%;
border-collapse: collapse;
font-size: 12.5px;
margin-top: 4px;
border-radius: 8px;
overflow: hidden;
border: 1px solid var(--line);
}
table.fn-mt thead {
background: var(--bg-card-alt);
}
table.fn-mt th {
text-align: left;
padding: 9px 12px;
font-size: 11px;
letter-spacing: 0.8px;
text-transform: uppercase;
font-weight: 700;
color: var(--ink-soft);
border-bottom: 1px solid var(--line);
}
table.fn-mt th.fn-col { background: #ecfdf5; color: #047857; }
table.fn-mt th.mt-col { background: #eff6ff; color: #1d4ed8; }
table.fn-mt td {
padding: 8px 12px;
border-bottom: 1px solid #e2e8f0;
vertical-align: top;
font-family: "SF Mono", Menlo, Consolas, monospace;
font-size: 12px;
}
table.fn-mt tr:last-child td { border-bottom: none; }
table.fn-mt tr:nth-child(even) td { background: #fafbfc; }
table.fn-mt td .desc {
font-family: -apple-system, sans-serif;
color: var(--ink-mute);
font-size: 11px;
display: block;
margin-top: 2px;
}
/* Footer */
footer {
text-align: center;
padding: 30px 20px;
color: #64748b;
font-size: 13px;
border-top: 1px solid rgba(148, 163, 184, 0.1);
margin-top: 60px;
}
footer code {
background: rgba(148,163,184,0.15);
padding: 2px 6px;
border-radius: 4px;
font-family: "SF Mono", Menlo, monospace;
color: #94a3b8;
}
/* Back to top */
.totop {
position: fixed;
bottom: 24px;
right: 24px;
width: 46px; height: 46px;
border-radius: 50%;
background: var(--accent);
color: white;
border: none;
cursor: pointer;
font-size: 20px;
opacity: 0;
pointer-events: none;
transition: all 0.3s ease;
z-index: 90;
box-shadow: 0 6px 20px rgba(20, 184, 166, 0.5);
}
.totop.show { opacity: 1; pointer-events: auto; }
.totop:hover { background: var(--accent-2); transform: translateY(-2px); }
/* Pillar banner animation */
@keyframes fadeUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
section.anchor { animation: fadeUp 0.6s ease both; }
@media (max-width: 600px) {
.topbar-inner { padding: 12px 16px; }
nav.main-nav a { padding: 6px 10px; font-size: 12px; }
main { padding: 20px 14px 60px; }
.section-head h2 { font-size: 24px; }
.type-grid { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<header class="topbar">
<div class="topbar-inner">
<div class="brand">
<div class="brand-mark">Py</div>
<div class="brand-text">
<h1>Python Data Types</h1>
<p>Interactive Educational Dashboard</p>
</div>
</div>
<nav class="main-nav">
<a href="#big-picture">Big Picture</a>
<a href="#fvm">Functions vs Methods</a>
<a href="#none">NoneType</a>
<a href="#single">Single Value</a>
<a href="#multiple">Multiple Value</a>
</nav>
</div>
</header>
<main>
<!-- ============ BIG PICTURE ============ -->
<section id="big-picture" class="anchor">
<div class="section-head">
<div class="section-title">Section 1</div>
<h2>The Big Picture</h2>
<p>Python's data types organise into three architectural pillars. Click any node below to dive into its detailed breakdown.</p>
</div>
<div class="tree-wrap">
<div class="tree">
<!-- Root -->
<div class="node root" data-target="#none">Python Data Types</div>
<!-- Three pillars -->
<div class="tier">
<div class="pillar-block">
<div class="node pillar none" data-target="#none">NoneType</div>
<div class="leaf-group">
<div class="node leaf none-type" data-target="#none">None</div>
</div>
</div>
<div class="pillar-block">
<div class="node pillar single" data-target="#single">Single Value Types</div>
<div class="leaf-group">
<div class="node leaf int" data-target="#int">int</div>
<div class="node leaf float" data-target="#float">float</div>
<div class="node leaf complex" data-target="#complex">complex</div>
<div class="node leaf bool" data-target="#bool">bool</div>
</div>
</div>
<div class="pillar-block">
<div class="node pillar multiple" data-target="#multiple">Multiple Value Types</div>
<div class="leaf-group">
<div class="node leaf str" data-target="#str">str</div>
<div class="node leaf list" data-target="#list">list</div>
<div class="node leaf tuple" data-target="#tuple">tuple</div>
<div class="node leaf set" data-target="#set">set</div>
<div class="node leaf dict" data-target="#dict">dict</div>
</div>
</div>
</div>
</div>
<div class="legend">
<span class="legend-item"><span class="legend-dot" style="background:linear-gradient(135deg,#64748b,#475569)"></span>Absence of value</span>
<span class="legend-item"><span class="legend-dot" style="background:linear-gradient(135deg,#f59e0b,#d97706)"></span>One scalar value</span>
<span class="legend-item"><span class="legend-dot" style="background:linear-gradient(135deg,#ec4899,#be185d)"></span>Collection of values</span>
</div>
</div>
<!-- ============ FVM STRIP ============ -->
<div class="fvm-strip anchor" id="fvm">
<div class="fvm-card fn">
<h3>Function <span class="badge">Standalone</span></h3>
<p>A standalone block of code, called by name. The data is passed <em>into</em> it as an argument. Functions live in the global/builtin namespace and work on many types.</p>
<span class="signature"><span class="b">len</span>(my_list) <span class="c"># builtin function, data passed in</span>
<span class="b">sorted</span>(my_list)
<span class="b">sum</span>([<span class="n">1</span>, <span class="n">2</span>, <span class="n">3</span>])</span>
</div>
<div class="fvm-card mt">
<h3>Method <span class="badge">Bound to Object</span></h3>
<p>A function <em>attached to</em> a specific object/type, called via dot notation. The object itself is the implicit first argument (<code>self</code>) and may mutate the object in place.</p>
<span class="signature">my_list.<span class="m">append</span>(<span class="n">42</span>) <span class="c"># method, object owns the call</span>
my_str.<span class="m">upper</span>()
my_dict.<span class="m">keys</span>()</span>
</div>
</div>
</section>
<!-- ============ NoneType PILLAR ============ -->
<section id="none" class="anchor pillar-section">
<div class="pillar-banner none">
<div class="pb-num">01</div>
<div>
<h3>NoneType</h3>
<p>The presence of absence — exactly one singleton value: <code style="background:rgba(255,255,255,0.18);padding:1px 6px;border-radius:4px">None</code></p>
</div>
</div>
<div class="type-grid">
<!-- ====== NONE ====== -->
<article class="type-card none" id="card-none">
<div class="card-head">
<div class="type-name">
<span class="py-name">None</span>
<span class="label">— the singleton null value</span>
</div>
<span class="mut-tag imm">Immutable · Singleton</span>
<p class="core"><strong>Core distinction:</strong> <code>None</code> is the <em>only</em> instance of <code>NoneType</code>. It represents "no value here" — used for missing data, default parameters, and as the implicit return of functions that don't explicitly return. Always compare with <code>is None</code>, never <code>== None</code>.</p>
</div>
<div class="card-body">
<h4>5 Real-World Examples</h4>
<pre class="code"><code><span class="tok-c"># 1) Sentinel for "no result" from a function</span>
<span class="tok-k">def</span> <span class="tok-m">find_user</span>(user_id):
<span class="tok-k">if</span> user_id <span class="tok-k">not in</span> database:
<span class="tok-k">return</span> <span class="tok-k">None</span>
<span class="tok-k">return</span> database[user_id]
result = find_user(<span class="tok-n">999</span>)
<span class="tok-k">if</span> result <span class="tok-k">is</span> <span class="tok-k">None</span>:
<span class="tok-b">print</span>(<span class="tok-s">"User not found"</span>)
<span class="tok-out"># User not found</span></code></pre>
<pre class="code"><code><span class="tok-c"># 2) Default parameter value (mutable-default avoidance)</span>
<span class="tok-k">def</span> <span class="tok-m">append_item</span>(item, target=<span class="tok-k">None</span>):
<span class="tok-k">if</span> target <span class="tok-k">is</span> <span class="tok-k">None</span>:
target = [] <span class="tok-c"># fresh list each call</span>
target.append(item)
<span class="tok-k">return</span> target
<span class="tok-b">print</span>(append_item(<span class="tok-n">1</span>)) <span class="tok-out"># [1]</span>
<span class="tok-b">print</span>(append_item(<span class="tok-n">2</span>)) <span class="tok-out"># [2] -- NOT [1, 2]</span></code></pre>
<pre class="code"><code><span class="tok-c"># 3) Placeholder while building a structure</span>
user = {<span class="tok-s">"name"</span>: <span class="tok-s">"Ada"</span>, <span class="tok-s">"email"</span>: <span class="tok-k">None</span>}
<span class="tok-c"># email collected later in the form flow</span>
user[<span class="tok-s">"email"</span>] = <span class="tok-s">"ada@example.com"</span>
<span class="tok-b">print</span>(user)
<span class="tok-out"># {'name': 'Ada', 'email': 'ada@example.com'}</span></code></pre>
<pre class="code"><code><span class="tok-c"># 4) Discarding a function's return value explicitly</span>
<span class="tok-k">def</span> <span class="tok-m">log</span>(msg):
<span class="tok-b">print</span>(<span class="tok-s">"[LOG]"</span>, msg)
<span class="tok-c"># no return -> implicitly returns None</span>
outcome = log(<span class="tok-s">"booting up"</span>)
<span class="tok-b">print</span>(outcome <span class="tok-k">is</span> <span class="tok-k">None</span>)
<span class="tok-out"># True</span></code></pre>
<pre class="code"><code><span class="tok-c"># 5) Clearing a variable's reference without deleting it</span>
cache = {<span class="tok-s">"a"</span>: <span class="tok-n">1</span>, <span class="tok-s">"b"</span>: <span class="tok-n">2</span>}
cache = <span class="tok-k">None</span> <span class="tok-c"># release reference, allow GC</span>
<span class="tok-b">print</span>(<span class="tok-b">type</span>(cache))
<span class="tok-out"># <class 'NoneType'></span>
<span class="tok-b">print</span>(<span class="tok-b">bool</span>(cache))
<span class="tok-out"># False (None is falsy)</span></code></pre>
<h4>Functions vs Methods</h4>
<table class="fn-mt">
<thead>
<tr><th class="fn-col">Built-in Functions (accept None)</th><th class="mt-col">NoneType Methods</th></tr>
</thead>
<tbody>
<tr>
<td><code>bool(None)</code><span class="desc">→ False (None is falsy)</span></td>
<td><em>(none)</em><span class="desc">NoneType intentionally exposes zero methods — it has no behaviour to invoke.</span></td>
</tr>
<tr>
<td><code>type(None)</code><span class="desc">→ <class 'NoneType'></span></td>
<td><em>(none)</em><span class="desc">All interaction happens via operators and built-ins, not methods.</span></td>
</tr>
<tr>
<td><code>id(None)</code><span class="desc">Always returns the same id — singleton</span></td>
<td><em>(none)</em></td>
</tr>
<tr>
<td><code>print(None)</code><span class="desc">→ prints "None"</span></td>
<td><em>(none)</em></td>
</tr>
<tr>
<td><code>str(None)</code><span class="desc">→ "None" (string form)</span></td>
<td><em>(none)</em></td>
</tr>
</tbody>
</table>
</div>
</article>
</div>
</section>
<!-- ============ SINGLE VALUE PILLAR ============ -->
<section id="single" class="anchor pillar-section">
<div class="pillar-banner single">
<div class="pb-num">02</div>
<div>
<h3>Single Value Data Types</h3>
<p>Scalars — each object holds exactly one atomic value at a time.</p>
</div>
</div>
<div class="type-grid">
<!-- ====== INT ====== -->
<article class="type-card int" id="int">
<div class="card-head">
<div class="type-name">
<span class="py-name">int</span>
<span class="label">— arbitrary-precision integer</span>
</div>
<span class="mut-tag imm">Immutable</span>
<p class="core"><strong>Core distinction:</strong> Whole numbers with <em>no size limit</em> (Python 3 auto-promotes beyond 64 bits). Use for counting, indexing, IDs, and exact integer math. No overflow — only your RAM limits you.</p>
</div>
<div class="card-body">
<h4>5 Real-World Examples</h4>
<pre class="code"><code><span class="tok-c"># 1) Basic arithmetic with operator precedence</span>
total = <span class="tok-n">7</span> + <span class="tok-n">3</span> * <span class="tok-n">2</span> <span class="tok-c"># 13, not 20</span>
remainder = <span class="tok-n">17</span> % <span class="tok-n">5</span> <span class="tok-c"># 2 (modulo)</span>
power = <span class="tok-n">2</span> ** <span class="tok-n">10</span> <span class="tok-c"># 1024</span>
<span class="tok-b">print</span>(total, remainder, power)
<span class="tok-out"># 13 2 1024</span></code></pre>
<pre class="code"><code><span class="tok-c"># 2) Arbitrary precision -- no overflow ever</span>
big = <span class="tok-n">2</span> ** <span class="tok-n">100</span>
<span class="tok-b">print</span>(big)
<span class="tok-out"># 1267650600228229401496703205376</span>
<span class="tok-b">print</span>(big * big)
<span class="tok-out"># 1606938044258990275541962092341162602522202993782792835301376</span></code></pre>
<pre class="code"><code><span class="tok-c"># 3) Parsing strings to int with a base</span>
decimal = <span class="tok-b">int</span>(<span class="tok-s">"255"</span>) <span class="tok-c"># 255 (base 10)</span>
binary = <span class="tok-b">int</span>(<span class="tok-s">"11111111"</span>, <span class="tok-n">2</span>) <span class="tok-c"># 255 (base 2)</span>
hexnum = <span class="tok-b">int</span>(<span class="tok-s">"ff"</span>, <span class="tok-n">16</span>) <span class="tok-c"># 255 (base 16)</span>
<span class="tok-b">print</span>(decimal, binary, hexnum)
<span class="tok-out"># 255 255 255</span></code></pre>
<pre class="code"><code><span class="tok-c"># 4) Floor division and divmod for splitting</span>
cookies = <span class="tok-n">23</span>
kids = <span class="tok-n">4</span>
each, leftover = <span class="tok-b">divmod</span>(cookies, kids)
<span class="tok-b">print</span>(<span class="tok-s">f"Each gets </span>{each}<span class="tok-s">, leftover </span>{leftover}<span class="tok-s">"</span>)
<span class="tok-out"># Each gets 5, leftover 3</span></code></pre>
<pre class="code"><code><span class="tok-c"># 5) Bitwise operations on flags</span>
READ, WRITE, EXEC = <span class="tok-n">1</span>, <span class="tok-n">2</span>, <span class="tok-n">4</span>
perm = READ | WRITE <span class="tok-c"># 3</span>
can_write = <span class="tok-b">bool</span>(perm & WRITE) <span class="tok-c"># True</span>
<span class="tok-b">print</span>(<span class="tok-b">bin</span>(perm), can_write)
<span class="tok-out"># 0b11 True</span>
<span class="tok-b">print</span>((<span class="tok-n">255</span>).bit_count()) <span class="tok-out"># 8 ones in binary</span></code></pre>
<h4>Functions vs Methods</h4>
<table class="fn-mt">
<thead>
<tr><th class="fn-col">Built-in Functions</th><th class="mt-col">int Methods</th></tr>
</thead>
<tbody>
<tr>
<td><code>int("42")</code><span class="desc">constructor / parser</span></td>
<td><code>(42).bit_length()</code><span class="desc">bits needed to represent</span></td>
</tr>
<tr>
<td><code>abs(-7)</code><span class="desc">→ 7</span></td>
<td><code>(42).bit_count()</code><span class="desc">count of 1-bits (3.10+)</span></td>
</tr>
<tr>
<td><code>pow(2, 10)</code><span class="desc">→ 1024</span></td>
<td><code>(255).to_bytes(2, "big")</code><span class="desc">serialise to bytes</span></td>
</tr>
<tr>
<td><code>divmod(23, 4)</code><span class="desc">→ (5, 3)</span></td>
<td><code>int.from_bytes(b"\x00\xff", "big")</code><span class="desc">deserialise from bytes</span></td>
</tr>
<tr>
<td><code>bin(10)</code> / <code>hex(255)</code><span class="desc">string representations</span></td>
<td><code>(42).conjugate()</code><span class="desc">→ 42 (int is own conjugate)</span></td>
</tr>
</tbody>
</table>
</div>
</article>
<!-- ====== FLOAT ====== -->
<article class="type-card float" id="float">
<div class="card-head">
<div class="type-name">
<span class="py-name">float</span>
<span class="label">— IEEE-754 double precision</span>
</div>
<span class="mut-tag imm">Immutable</span>
<p class="core"><strong>Core distinction:</strong> 64-bit floating point (≈15-17 significant digits). Use for measurements, scientific math, fractions. Carries rounding artefacts — never use <code>==</code> on floats, use <code>math.isclose</code>.</p>
</div>
<div class="card-body">
<h4>5 Real-World Examples</h4>
<pre class="code"><code><span class="tok-c"># 1) Fractional arithmetic -- note rounding artefacts</span>
<span class="tok-b">print</span>(<span class="tok-n">0.1</span> + <span class="tok-n">0.2</span>)
<span class="tok-out"># 0.30000000000000004 (NOT 0.3!)</span>
<span class="tok-k">import</span> math
<span class="tok-b">print</span>(math.isclose(<span class="tok-n">0.1</span> + <span class="tok-n">0.2</span>, <span class="tok-n">0.3</span>))
<span class="tok-out"># True (correct way to compare floats)</span></code></pre>
<pre class="code"><code><span class="tok-c"># 2) Scientific notation for huge / tiny numbers</span>
speed_of_light = <span class="tok-n">2.998e8</span> <span class="tok-c"># m/s == 299_800_000.0</span>
planck = <span class="tok-n">6.626e-34</span> <span class="tok-c"># J·s == 0.000...06626</span>
<span class="tok-b">print</span>(speed_of_light, planck)
<span class="tok-out"># 299800000.0 6.626e-34</span></code></pre>
<pre class="code"><code><span class="tok-c"># 3) Special values: infinity and NaN</span>
inf = <span class="tok-b">float</span>(<span class="tok-s">"inf"</span>)
nan = <span class="tok-b">float</span>(<span class="tok-s">"nan"</span>)
<span class="tok-b">print</span>(inf > <span class="tok-n">10</span>**<span class="tok-n">100</span>) <span class="tok-out"># True</span>
<span class="tok-b">print</span>(nan == nan) <span class="tok-out"># False (NaN is never equal to itself)</span>
<span class="tok-b">print</span>(math.isnan(nan)) <span class="tok-out"># True</span></code></pre>
<pre class="code"><code><span class="tok-c"># 4) Rounding for display / currency</span>
price = <span class="tok-n">19.995</span>
<span class="tok-b">print</span>(<span class="tok-b">round</span>(price, <span class="tok-n">2</span>)) <span class="tok-out"># 20.0 (banker's rounding)</span>
<span class="tok-b">print</span>(<span class="tok-b">round</span>(<span class="tok-n">2.5</span>), <span class="tok-b">round</span>(<span class="tok-n">3.5</span>)) <span class="tok-out"># 2 4 (rounds to even)</span>
<span class="tok-c"># For money, use Decimal, not float:</span>
<span class="tok-k">from</span> decimal <span class="tok-k">import</span> Decimal
<span class="tok-b">print</span>(Decimal(<span class="tok-s">"19.995"</span>).quantize(Decimal(<span class="tok-s">"0.01"</span>))) <span class="tok-out"># 20.00</span></code></pre>
<pre class="code"><code><span class="tok-c"># 5) Float construction from fraction or string</span>
<span class="tok-k">from</span> fractions <span class="tok-k">import</span> Fraction
<span class="tok-b">print</span>(<span class="tok-b">float</span>(Fraction(<span class="tok-n">1</span>, <span class="tok-n">3</span>))) <span class="tok-out"># 0.3333333333333333</span>
<span class="tok-b">print</span>(<span class="tok-b">float</span>(<span class="tok-s">"3.14"</span>)) <span class="tok-c"># 3.14</span>
<span class="tok-b">print</span>((<span class="tok-n">3.14</span>).as_integer_ratio())
<span class="tok-out"># (7070651414971679, 2251799813685248)</span>
<span class="tok-b">print</span>((<span class="tok-n">5.0</span>).is_integer()) <span class="tok-out"># True</span></code></pre>
<h4>Functions vs Methods</h4>
<table class="fn-mt">
<thead>
<tr><th class="fn-col">Built-in Functions</th><th class="mt-col">float Methods</th></tr>
</thead>
<tbody>
<tr>
<td><code>float("3.14")</code><span class="desc">constructor / parser</span></td>
<td><code>(3.14).is_integer()</code><span class="desc">→ False (5.0 → True)</span></td>
</tr>
<tr>
<td><code>round(3.14159, 2)</code><span class="desc">→ 3.14</span></td>
<td><code>(3.14).as_integer_ratio()</code><span class="desc">exact fraction tuple</span></td>
</tr>
<tr>
<td><code>abs(-2.5)</code><span class="desc">→ 2.5</span></td>
<td><code>(3.14).hex()</code><span class="desc">hex float repr</span></td>
</tr>
<tr>
<td><code>pow(2.0, 0.5)</code><span class="desc">→ 1.414... (sqrt)</span></td>
<td><code>(3.14).conjugate()</code><span class="desc">→ 3.14 (compat with complex)</span></td>
</tr>
<tr>
<td><code>max(1.5, 2.7)</code><span class="desc">→ 2.7</span></td>
<td><code>float.fromhex("0x1.8p+1")</code><span class="desc">→ 3.0</span></td>
</tr>
</tbody>
</table>
</div>
</article>
<!-- ====== COMPLEX ====== -->
<article class="type-card complex" id="complex">
<div class="card-head">
<div class="type-name">
<span class="py-name">complex</span>
<span class="label">— real + imaginary (j)</span>
</div>
<span class="mut-tag imm">Immutable</span>
<p class="core"><strong>Core distinction:</strong> Pairs a real and imaginary float, written <code>a + bj</code>. Use for signal processing, electrical engineering (impedance), quantum mechanics, and 2D rotation. Python uses <code>j</code>, not <code>i</code>.</p>
</div>
<div class="card-body">
<h4>5 Real-World Examples</h4>
<pre class="code"><code><span class="tok-c"># 1) Creating complex numbers three ways</span>
z1 = <span class="tok-n">3</span> + <span class="tok-n">4j</span> <span class="tok-c"># literal</span>
z2 = <span class="tok-b">complex</span>(<span class="tok-n">3</span>, <span class="tok-n">4</span>) <span class="tok-c"># constructor</span>
z3 = <span class="tok-b">complex</span>(<span class="tok-s">"3+4j"</span>) <span class="tok-c"># from string</span>
<span class="tok-b">print</span>(z1, z2, z3, z1 == z2 == z3)
<span class="tok-out"># (3+4j) (3+4j) (3+4j) True</span></code></pre>
<pre class="code"><code><span class="tok-c"># 2) Accessing real and imaginary parts</span>
z = <span class="tok-n">5</span> - <span class="tok-n">2j</span>
<span class="tok-b">print</span>(z.real, <span class="tok-b">type</span>(z.real)) <span class="tok-out"># 5.0 <class 'float'></span>
<span class="tok-b">print</span>(z.imag, <span class="tok-b">type</span>(z.imag)) <span class="tok-out"># -2.0 <class 'float'></span>
<span class="tok-b">print</span>(<span class="tok-b">abs</span>(z)) <span class="tok-c"># |z| = sqrt(5^2 + 2^2)</span>
<span class="tok-out"># 5.385164807134504</span></code></pre>
<pre class="code"><code><span class="tok-c"># 3) Arithmetic: addition & multiplication behave geometrically</span>
a = <span class="tok-n">1</span> + <span class="tok-n">1j</span>
b = <span class="tok-n">1</span> - <span class="tok-n">1j</span>
<span class="tok-b">print</span>(a + b) <span class="tok-out"># 2+0j (vector add)</span>
<span class="tok-b">print</span>(a * b) <span class="tok-out"># 2+0j (|a|*|b| since b = conj(a))</span>
<span class="tok-b">print</span>(a.conjugate()) <span class="tok-out"># 1-1j (flips imaginary sign)</span></code></pre>
<pre class="code"><code><span class="tok-c"># 4) Electrical impedance: Z = R + jX</span>
resistor = <span class="tok-n">100</span> + <span class="tok-n">0j</span> <span class="tok-c"># pure resistor</span>
inductor = <span class="tok-n">0</span> + <span class="tok-n">50j</span> <span class="tok-c"># X_L = +50 ohm</span>
capacitor = <span class="tok-n">0</span> - <span class="tok-n">30j</span> <span class="tok-c"># X_C = -30 ohm</span>
total_impedance = resistor + inductor + capacitor
<span class="tok-b">print</span>(total_impedance)