diff --git a/README.md b/README.md index cd0d72e..6905313 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -

+

+ + + + Shows a wtfpython logo. + +

What the f*ck Python! 😱

Exploring and understanding Python through surprising snippets.

@@ -352,11 +358,13 @@ Makes sense, right? * All length 0 and length 1 strings are interned. * Strings are interned at compile time (`'wtf'` will be interned but `''.join(['w', 't', 'f'])` will not be interned) * 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) - - - - Shows a string interning process. - +

+ + + + Shows a string interning process. + +

+ 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). + 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? When we initialize `row` variable, this visualization explains what happens in the memory -![image](/images/tic-tac-toe/after_row_initialized.png) +

+ + + + Shows a memory segment after row is initialized. + +

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`) -![image](/images/tic-tac-toe/after_board_initialized.png) +

+ + + + Shows a memory segment after board is initialized. + +

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). diff --git a/images/logo-dark.png b/images/logo-dark.png deleted file mode 100644 index 9d7791f..0000000 Binary files a/images/logo-dark.png and /dev/null differ diff --git a/images/logo.png b/images/logo.png deleted file mode 100644 index 014a63a..0000000 Binary files a/images/logo.png and /dev/null differ diff --git a/images/logo.svg b/images/logo.svg new file mode 100755 index 0000000..6ec5eda --- /dev/null +++ b/images/logo.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/logo_dark_theme.svg b/images/logo_dark_theme.svg new file mode 100755 index 0000000..f89e797 --- /dev/null +++ b/images/logo_dark_theme.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/tic-tac-toe/after_board_initialized.png b/images/tic-tac-toe/after_board_initialized.png deleted file mode 100644 index 616747f..0000000 Binary files a/images/tic-tac-toe/after_board_initialized.png and /dev/null differ diff --git a/images/tic-tac-toe/after_board_initialized.svg b/images/tic-tac-toe/after_board_initialized.svg new file mode 100755 index 0000000..02b1dad --- /dev/null +++ b/images/tic-tac-toe/after_board_initialized.svg @@ -0,0 +1,4 @@ + + + +
" "
" "
" "
" "
" "
" "
row
row
board[0]
board[0]
board[1]
board[1]
board[2]
board[2]
Text is not SVG - cannot display
\ No newline at end of file diff --git a/images/tic-tac-toe/after_board_initialized_dark_theme.svg b/images/tic-tac-toe/after_board_initialized_dark_theme.svg new file mode 100755 index 0000000..3218ad0 --- /dev/null +++ b/images/tic-tac-toe/after_board_initialized_dark_theme.svg @@ -0,0 +1,4 @@ + + + +
" "
" "
" "
" "
" "
" "
row
row
board[0]
board[0]
board[1]
board[1]
board[2]
board[2]
Text is not SVG - cannot display
\ No newline at end of file diff --git a/images/tic-tac-toe/after_row_initialized.png b/images/tic-tac-toe/after_row_initialized.png deleted file mode 100644 index 520d700..0000000 Binary files a/images/tic-tac-toe/after_row_initialized.png and /dev/null differ diff --git a/images/tic-tac-toe/after_row_initialized.svg b/images/tic-tac-toe/after_row_initialized.svg new file mode 100755 index 0000000..92eb02c --- /dev/null +++ b/images/tic-tac-toe/after_row_initialized.svg @@ -0,0 +1,4 @@ + + + +
" "
" "
" "
" "
" "
" "
row
row
Text is not SVG - cannot display
\ No newline at end of file diff --git a/images/tic-tac-toe/after_row_initialized_dark_theme.svg b/images/tic-tac-toe/after_row_initialized_dark_theme.svg new file mode 100755 index 0000000..2404958 --- /dev/null +++ b/images/tic-tac-toe/after_row_initialized_dark_theme.svg @@ -0,0 +1,4 @@ + + + +
" "
" "
" "
" "
" "
" "
row
row
Text is not SVG - cannot display
\ No newline at end of file