└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Python Secrets 2 | Curated list of all the hidden jokes, easter eggs, secrets and the lesser known things in Python 3 | 4 | 5 | ## Table of Contents 6 | - [Did you know?](#did-you-know) 7 | - [Easter Eggs](#easter-eggs) 8 | - [Misc.](#misc) 9 | 10 | 11 | ## Did you know? 12 | 13 | ### 1. You can't subclass bool 14 | ```py 15 | >>> class subclass_of_bool(bool): 16 | ... pass 17 | ... 18 | Traceback (most recent call last): 19 | File "", line 1, in 20 | TypeError: type 'bool' is not an acceptable base type 21 | ``` 22 | 23 | ### 2. Oxford 15 24 | ``` 25 | >>> 0xfor~d 26 | 15 27 | ``` 28 | 29 | Now try tipping the 0xfedor-a 🎩 30 | 31 | ### 3. Unicode identifiers 32 | ```py 33 | π = 3.1415 34 | area = π * r ** 2 35 | ``` 36 | 37 | ### 4. Longs 38 | 39 | ```py 40 | >>> p = 256 41 | >>> q = 256 42 | >>> p is q 43 | True 44 | >>> p = 257 45 | >>> q = 257 46 | >>> p is q 47 | False 48 | ``` 49 | 50 | ### 4.CLI month calendar 51 | 52 | ```bash 53 | python -m "calendar" 2021 7 54 | ``` 55 | For options: `python -m "calendar" --help` 56 | 57 | ## Easter Eggs 58 | 59 | ### 1. Zen of Python 60 | ```py 61 | import this 62 | ``` 63 | 64 | ### 2. Easiest Hello World 65 | ```py 66 | import __hello__ 67 | ``` 68 | 69 | ### 3. Braces in python? 70 | ```py 71 | from __future__ import braces 72 | File "", line 1 73 | SyntaxError: not a chance 74 | ``` 75 | 76 | ### 4. InPynite? 77 | ```py 78 | >>> hash(float('inf')) 79 | 314159 80 | >>> hash(float('nan')) 81 | 0 82 | ``` 83 | 84 | ### 5. Antigravity 85 | ```py 86 | import antigravity 87 | ``` 88 | 89 | ### 6. Random coordinates 90 | ```py 91 | >>> from antigravity import geohash 92 | >>> print(geohash(37.421542, -122.085589, b'2005-05-26-10458.68')) 93 | # 37.857713 -122.544543 94 | ``` 95 | 96 | ### 7. Friendly Language Uncle For Life 97 | ```py 98 | >>> from __future__ import barry_as_FLUFL 99 | >>> 1 != 3 100 | File "", line 1 101 | 1 != 3 102 | ^ 103 | SyntaxError: with Barry as BDFL, use '<>' instead of '!=' 104 | >>> 1 <> 3 105 | True 106 | ``` 107 | ### 8. New parser? 108 | ```py 109 | >>> __peg_parser__ 110 | File "", line 1 111 | __peg_parser__ 112 | ^ 113 | SyntaxError: You found it! 114 | ``` 115 | Note: This will work only in 3.9 and will be removed in 3.10 along with the LL(1) parser with the introduction of the new PEG parser. 116 | 117 | ### 9. Not for the faint of heart 118 | ```py 119 | >>> import types 120 | >>> help(types.CodeType) 121 | ``` 122 | 123 | 124 | ## Misc. 125 | 126 | ### 1. If statement without using an if 127 | ```py 128 | # 1 condition 129 | ['cond1 is false', 'cond1 is true'][cond1] 130 | 131 | # 2 conditions 132 | ['both false', 'cond1 is true', 'cond2 is true', 'both true'][2*cond2 + cond1] 133 | ``` 134 | 135 | ### 2. For loop without using for, while 136 | ```py 137 | def loop(array): 138 | if len(array) == 0: 139 | return 0 140 | else: 141 | # do smth with array[0] for example print(array[0]) 142 | print(array[0]) 143 | return loop(array[1:]) 144 | 145 | loop([1,2,3,'a string']) 146 | ``` 147 | --------------------------------------------------------------------------------