Skip to content

Commit daf7ccd

Browse files
committed
Use new theme specific logic for images
1 parent b471c9f commit daf7ccd

11 files changed

Lines changed: 120 additions & 8 deletions

β€ŽREADME.mdβ€Ž

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
<p align="center"><img src="/images/logo.png#gh-light-mode-only" alt=""><img src="/images/logo-dark.png#gh-dark-mode-only" alt=""></p>
1+
<p align="center">
2+
<picture>
3+
<source media="(prefers-color-scheme: dark)" srcset="/images/logo_dark_theme.svg">
4+
<source media="(prefers-color-scheme: light)" srcset="/images/logo.svg">
5+
<img alt="Shows a wtfpython logo." src="/images/logo.svg">
6+
</picture>
7+
</p>
28
<h1 align="center">What the f*ck Python! 😱</h1>
39
<p align="center">Exploring and understanding Python through surprising snippets.</p>
410

@@ -352,11 +358,13 @@ Makes sense, right?
352358
* All length 0 and length 1 strings are interned.
353359
* Strings are interned at compile time (`'wtf'` will be interned but `''.join(['w', 't', 'f'])` will not be interned)
354360
* Strings that are not composed of ASCII letters, digits or underscores, are not interned. This explains why `'wtf!'` was not interned due to `!`. CPython implementation of this rule can be found [here](https://github.com/python/cpython/blob/3.6/Objects/codeobject.c#L19)
355-
<picture>
356-
<source media="(prefers-color-scheme: dark)" srcset="/images/string-intern/string_interning_dark_theme.svg">
357-
<source media="(prefers-color-scheme: light)" srcset="/images/string-intern/string_interning.svg">
358-
<img alt="Shows a string interning process." src="/images/string-intern/string_interning.svg">
359-
</picture>
361+
<p align="center">
362+
<picture>
363+
<source media="(prefers-color-scheme: dark)" srcset="/images/string-intern/string_interning_dark_theme.svg">
364+
<source media="(prefers-color-scheme: light)" srcset="/images/string-intern/string_interning.svg">
365+
<img alt="Shows a string interning process." src="/images/string-intern/string_interning.svg">
366+
</picture>
367+
</p>
360368
361369
+ When `a` and `b` are set to `"wtf!"` in the same line, the Python interpreter creates a new object, then references the second variable at the same time. If you do it on separate lines, it doesn't "know" that there's already `"wtf!"` as an object (because `"wtf!"` is not implicitly interned as per the facts mentioned above). It's a compile-time optimization. This optimization doesn't apply to 3.7.x versions of CPython (check this [issue](https://github.com/satwikkansal/wtfpython/issues/100) for more discussion).
362370
+ A compile unit in an interactive environment like IPython consists of a single statement, whereas it consists of the entire module in case of modules. `a, b = "wtf!", "wtf!"` is single statement, whereas `a = "wtf!"; b = "wtf!"` are two statements in a single line. This explains why the identities are different in `a = "wtf!"; b = "wtf!"`, and also explain why they are same when invoked in `some_file.py`
@@ -980,11 +988,23 @@ We didn't assign three `"X"`s, did we?
980988
981989
When we initialize `row` variable, this visualization explains what happens in the memory
982990
983-
![image](/images/tic-tac-toe/after_row_initialized.png)
991+
<p align="center">
992+
<picture>
993+
<source media="(prefers-color-scheme: dark)" srcset="/images/tic-tac-toe/after_row_initializedlogo_dark_theme.svg">
994+
<source media="(prefers-color-scheme: light)" srcset="/images/tic-tac-toe/after_row_initializedlogo.svg">
995+
<img alt="Shows a memory segment after row is initialized." src="/images/tic-tac-toe/after_row_initialized.svg">
996+
</picture>
997+
</p>
984998
985999
And when the `board` is initialized by multiplying the `row`, this is what happens inside the memory (each of the elements `board[0]`, `board[1]` and `board[2]` is a reference to the same list referred by `row`)
9861000
987-
![image](/images/tic-tac-toe/after_board_initialized.png)
1001+
<p align="center">
1002+
<picture>
1003+
<source media="(prefers-color-scheme: dark)" srcset="/images/tic-tac-toe/after_board_initialized_dark_theme.svg">
1004+
<source media="(prefers-color-scheme: light)" srcset="/images/tic-tac-toe/after_board_initialized.svg">
1005+
<img alt="Shows a memory segment after board is initialized." src="/images/tic-tac-toe/after_board_initialized.svg">
1006+
</picture>
1007+
</p>
9881008
9891009
We can avoid this scenario here by not using `row` variable to generate `board`. (Asked in [this](https://github.com/satwikkansal/wtfpython/issues/68) issue).
9901010

β€Žimages/logo-dark.pngβ€Ž

-12.7 KB
Binary file not shown.

β€Žimages/logo.pngβ€Ž

-8.12 KB
Binary file not shown.

β€Žimages/logo.svgβ€Ž

Lines changed: 38 additions & 0 deletions
Loading

β€Žimages/logo_dark_theme.svgβ€Ž

Lines changed: 38 additions & 0 deletions
Loading
-159 KB
Binary file not shown.

β€Žimages/tic-tac-toe/after_board_initialized.svgβ€Ž

Lines changed: 4 additions & 0 deletions
Loading

β€Žimages/tic-tac-toe/after_board_initialized_dark_theme.svgβ€Ž

Lines changed: 4 additions & 0 deletions
Loading
-50.5 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
Β (0)