Skip to content

Commit f220dd3

Browse files
committed
Update the description and add social links
1 parent b743451 commit f220dd3

1 file changed

Lines changed: 48 additions & 39 deletions

File tree

README.md

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1 align="center"> What the f*ck Python? 🐍 </h1>
2-
<p align="center"> A collection of interesting and tricky Python examples. </p>
2+
<p align="center"> An interesting collection of subtle and tricky Python Snippets. </p>
33

44
[![WTFPL 2.0][license-image]][license-url]
55

@@ -10,7 +10,7 @@ Here is a fun project attempting to collect such classic and tricky examples of
1010

1111
While some of the examples you see below may not be WTFs in the truest sense, but they'll reveal some of the interesting parts of Python that you might be unaware of. I find it a nice way to learn the internals of a programming language, and I think you'll find them interesting as well!
1212

13-
If you're an experienced Python programmer, you might be familiar with most of these examples, and I might be able to revive some sweet old memories of yours being bitten by these gotchas :sweat_smile:
13+
If you're an experienced Python programmer, you might be familiar with some of these examples, and I might be able to revive sweet old memories of yours being bitten by these gotchas :sweat_smile:
1414

1515
So, here ya go...
1616

@@ -35,92 +35,92 @@ So, here ya go...
3535
- [💡 Explanation:](#-explanation-1)
3636
- [Backslashes at the end of string](#backslashes-at-the-end-of-string)
3737
- [💡 Explanation](#-explanation-4)
38-
- [String interning](#string-interning)
38+
- [Strings can be tricky sometimes](#strings-can-be-tricky-sometimes)
3939
- [💡 Explanation:](#-explanation-2)
40+
- [`+=` is faster](#-is-faster)
41+
- [💡 Explanation:](#-explanation-3)
4042
- [Let's make a giant string!](#lets-make-a-giant-string)
4143
- [💡 Explanation](#-explanation-5)
4244
- [Yes, it exists!](#yes-it-exists)
43-
- [💡 Explanation:](#-explanation-3)
44-
- [`is` is not what it is!](#is-is-not-what-it-is)
4545
- [💡 Explanation:](#-explanation-4)
46+
- [`is` is not what it is!](#is-is-not-what-it-is)
47+
- [💡 Explanation:](#-explanation-5)
4648
- [`is not ...` is not `is (not ...)`](#is-not--is-not-is-not-)
4749
- [💡 Explanation](#-explanation-6)
4850
- [The function inside loop sticks to the same output](#the-function-inside-loop-sticks-to-the-same-output)
4951
- [💡 Explanation](#-explanation-7)
5052
- [Loop variables leaking out of local scope!](#loop-variables-leaking-out-of-local-scope)
51-
- [💡 Explanation:](#-explanation-5)
52-
- [A tic-tac-toe where X wins in the first attempt!](#a-tic-tac-toe-where-x-wins-in-the-first-attempt)
5353
- [💡 Explanation:](#-explanation-6)
54-
- [Beware of default mutable arguments!](#beware-of-default-mutable-arguments)
54+
- [A tic-tac-toe where X wins in the first attempt!](#a-tic-tac-toe-where-x-wins-in-the-first-attempt)
5555
- [💡 Explanation:](#-explanation-7)
56-
- [Same operands, different story!](#same-operands-different-story)
56+
- [Beware of default mutable arguments!](#beware-of-default-mutable-arguments)
5757
- [💡 Explanation:](#-explanation-8)
58-
- [Mutating the immutable!](#mutating-the-immutable)
58+
- [Same operands, different story!](#same-operands-different-story)
5959
- [💡 Explanation:](#-explanation-9)
60-
- [Using a variable not defined in scope](#using-a-variable-not-defined-in-scope)
60+
- [Mutating the immutable!](#mutating-the-immutable)
6161
- [💡 Explanation:](#-explanation-10)
62-
- [The disappearing variable from outer scope](#the-disappearing-variable-from-outer-scope)
62+
- [Using a variable not defined in scope](#using-a-variable-not-defined-in-scope)
6363
- [💡 Explanation:](#-explanation-11)
64-
- [Return return everywhere!](#return-return-everywhere)
64+
- [The disappearing variable from outer scope](#the-disappearing-variable-from-outer-scope)
6565
- [💡 Explanation:](#-explanation-12)
66-
- [When True is actually False](#when-true-is-actually-false)
66+
- [Return return everywhere!](#return-return-everywhere)
6767
- [💡 Explanation:](#-explanation-13)
68-
- [Be careful with chained operations](#be-careful-with-chained-operations)
68+
- [When True is actually False](#when-true-is-actually-false)
6969
- [💡 Explanation:](#-explanation-14)
70+
- [Be careful with chained operations](#be-careful-with-chained-operations)
71+
- [💡 Explanation:](#-explanation-15)
7072
- [Name resolution ignoring class scope](#name-resolution-ignoring-class-scope)
7173
- [💡 Explanation](#-explanation-8)
7274
- [From filled to None in one instruction...](#from-filled-to-none-in-one-instruction)
7375
- [💡 Explanation](#-explanation-9)
7476
- [Explicit typecast of strings](#explicit-typecast-of-strings)
75-
- [💡 Explanation:](#-explanation-15)
76-
- [Class attributes and instance attributes](#class-attributes-and-instance-attributes)
7777
- [💡 Explanation:](#-explanation-16)
78+
- [Class attributes and instance attributes](#class-attributes-and-instance-attributes)
79+
- [💡 Explanation:](#-explanation-17)
7880
- [Catching the Exceptions!](#catching-the-exceptions)
7981
- [💡 Explanation](#-explanation-10)
8082
- [Midnight time doesn't exist?](#midnight-time-doesnt-exist)
81-
- [💡 Explanation:](#-explanation-17)
82-
- [What's wrong with booleans?](#whats-wrong-with-booleans)
8383
- [💡 Explanation:](#-explanation-18)
84-
- [Needle in a Haystack](#needle-in-a-haystack)
84+
- [What's wrong with booleans?](#whats-wrong-with-booleans)
8585
- [💡 Explanation:](#-explanation-19)
86-
- [Teleportation](#teleportation)
86+
- [Needle in a Haystack](#needle-in-a-haystack)
8787
- [💡 Explanation:](#-explanation-20)
88-
- [yielding None](#yielding-none)
88+
- [Teleportation](#teleportation)
8989
- [💡 Explanation:](#-explanation-21)
90-
- [The surprising comma](#the-surprising-comma)
90+
- [yielding None](#yielding-none)
9191
- [💡 Explanation:](#-explanation-22)
92-
- [For what?](#for-what)
92+
- [The surprising comma](#the-surprising-comma)
9393
- [💡 Explanation:](#-explanation-23)
94-
- [not knot!](#not-knot)
94+
- [For what?](#for-what)
9595
- [💡 Explanation:](#-explanation-24)
96-
- [Subclass relationships](#subclass-relationships)
96+
- [not knot!](#not-knot)
9797
- [💡 Explanation:](#-explanation-25)
98-
- [Mangling time!](#mangling-time)
98+
- [Subclass relationships](#subclass-relationships)
9999
- [💡 Explanation:](#-explanation-26)
100-
- [Deep down, we're all the same.](#deep-down-were-all-the-same)
100+
- [Mangling time!](#mangling-time)
101101
- [💡 Explanation:](#-explanation-27)
102-
- [Half triple-quoted strings](#half-triple-quoted-strings)
102+
- [Deep down, we're all the same.](#deep-down-were-all-the-same)
103103
- [💡 Explanation:](#-explanation-28)
104-
- [Implicity key type conversion](#implicity-key-type-conversion)
104+
- [Half triple-quoted strings](#half-triple-quoted-strings)
105105
- [💡 Explanation:](#-explanation-29)
106-
- [Stubborn `del` operator](#stubborn-del-operator)
106+
- [Implicity key type conversion](#implicity-key-type-conversion)
107107
- [💡 Explanation:](#-explanation-30)
108-
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
108+
- [Stubborn `del` operator](#stubborn-del-operator)
109109
- [💡 Explanation:](#-explanation-31)
110+
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
111+
- [💡 Explanation:](#-explanation-32)
110112
- [Minor Ones](#minor-ones)
111113
- [TODO: Hell of an example!](#todo-hell-of-an-example)
112114
- [Contributing](#contributing)
113115
- [Acknowledgements](#acknowledgements)
114116
- [Some nice Links!](#some-nice-links)
115117
- [🎓 License](#-license)
116-
- [Donation](#donation)
118+
- [Help](#help)
117119

118120
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
119121

120122
# Structure of the Examples
121123

122-
**Note:** All the examples mentioned below are tested on Python 3.5.2 interactive interpreter, and they should work for all the Python versions unless explicitly specified in the example description.
123-
124124
All the examples are structured like below:
125125

126126
> ### Some fancy Title
@@ -150,6 +150,7 @@ All the examples are structured like below:
150150
> # some justified output
151151
> ```
152152
153+
**Note:** All the examples mentioned below are tested on Python 3.5.2 interactive interpreter, and they should work for all the Python versions unless explicitly specified in the example description.
153154
154155
# Usage
155156
@@ -167,7 +168,7 @@ $ npm install -g wtfpython
167168
```
168169
Now, just run `wtfpython` at the command line which will open this collection in your selected `$PAGER`.
169170
170-
#TODO: Add pypi package for reading via command line
171+
#TODO: Add pypi package for reading via command line (yes, this is the real wtf for now!)
171172
172173
# 👀 Examples
173174
@@ -445,13 +446,18 @@ True
445446
>>> b = "wtf!"
446447
>>> a is b
447448
False
449+
450+
>>> a, b = "wtf!", "wtf!"
451+
>>> a is b
452+
True
448453
```
449454
450455
3\.
451456
```py
452457
>>> 'a' * 20 is 'aaaaaaaaaaaaaaaaaaaa'
453458
True
454459
>>> 'a' * 21 is 'aaaaaaaaaaaaaaaaaaaaa'
460+
False
455461
```
456462
457463
Makes sense, right?
@@ -463,6 +469,7 @@ Makes sense, right?
463469
* All length 0 and length 1 strings are interned.
464470
* Strings are interned at compile time (`'wtf'` will be interned but `''.join(['w', 't', 'f']` will not be interned)
465471
* Strings that are not composed of ascii letters, digits or underscores, are not interned. This explains why `'wtf!'` was not interned due to `!`.
472+
+ 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 compiler optimization and specifically applies to the interactive environment.
466473
467474
---
468475
@@ -2169,10 +2176,12 @@ The idea and design for this collection are inspired by Denys Dovhan's awesome p
21692176
[license-url]: http://www.wtfpl.net
21702177
[license-image]: https://img.shields.io/badge/License-WTFPL%202.0-lightgrey.svg?style=flat-square
21712178
2172-
# Donation
2179+
# Help
21732180
2174-
This project costed me nothing and doesn't require anything to operate. However, I'm looking for full-time opportunities, I'd **highly appreciate** if you can let me know about open positions around you.
2181+
Hey, I'm looking for full-time opportunities, I'd highly appreciate if you could do me a small favor by letting me know about open positions around you.
21752182
2176-
And finally, Thanks for reading this project, I hope you enjoyed it and found it informative!
2183+
And finally, Thanks a ton for reading this project, I hope you enjoyed it and found it informative!
21772184
2185+
Want to share What the f**k Python with friends?
21782186
2187+
[Twitter](https://twitter.com/intent/tweet?url=https://github.com/satwikkansal/wtfpython&hastags=python,wtfpython) | [Linkedin](https://www.linkedin.com/shareArticle?url=https://github.com/satwikkansal&title=What the f*ck Python!&summary=An interesting collection of subtle and tricky Python snippets.)

0 commit comments

Comments
 (0)