You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Be careful with chained operations](#be-careful-with-chained-operations)
68
+
-[When True is actually False](#when-true-is-actually-false)
71
69
-[💡 Explanation:](#-explanation-14)
70
+
-[Be careful with chained operations](#be-careful-with-chained-operations)
71
+
-[💡 Explanation:](#-explanation-15)
72
72
-[Name resolution ignoring class scope](#name-resolution-ignoring-class-scope)
73
-
-[💡 Explanation](#-explanation-1)
73
+
-[💡 Explanation](#-explanation-8)
74
74
-[From filled to None in one instruction...](#from-filled-to-none-in-one-instruction)
75
-
-[💡 Explanation](#-explanation-2)
75
+
-[💡 Explanation](#-explanation-9)
76
76
-[Explicit typecast of strings](#explicit-typecast-of-strings)
77
-
-[💡 Explanation:](#-explanation-15)
77
+
-[💡 Explanation:](#-explanation-16)
78
78
-[Class attributes and instance attributes](#class-attributes-and-instance-attributes)
79
-
-[Explanation:](#explanation-1)
79
+
-[💡 Explanation:](#-explanation-17)
80
80
-[Catching the Exceptions!](#catching-the-exceptions)
81
-
-[Explanation](#explanation-7)
81
+
-[💡 Explanation](#-explanation-10)
82
82
-[Midnight time doesn't exist?](#midnight-time-doesnt-exist)
83
-
-[💡 Explanation:](#-explanation-16)
83
+
-[💡 Explanation:](#-explanation-18)
84
84
-[Counting the booleans](#counting-the-booleans)
85
-
-[💡 Explanation:](#-explanation-17)
85
+
-[💡 Explanation:](#-explanation-19)
86
86
-[Needle in a Haystack](#needle-in-a-haystack)
87
-
-[💡 Explanation:](#-explanation-18)
87
+
-[💡 Explanation:](#-explanation-20)
88
88
-[Loop variable resilient to changes](#loop-variable-resilient-to-changes)
89
-
-[💡 Explanation:](#-explanation-19)
89
+
-[💡 Explanation:](#-explanation-21)
90
90
-[Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
91
-
-[💡 Explanation:](#-explanation-20)
91
+
-[💡 Explanation:](#-explanation-22)
92
92
-[Minor Ones](#minor-ones)
93
93
-[TODO: Hell of an example!](#todo-hell-of-an-example)
94
94
-[Contributing](#contributing)
@@ -166,7 +166,7 @@ Wut?
166
166
167
167
**Note:** The easiest way to reproduce this is to simply copy the statements from the above snippet and paste them into your file/shell.
168
168
169
-
#### Explanation
169
+
#### 💡 Explanation
170
170
171
171
Some Unicode characters look identical to ASCII ones, but are considered distinct by the interpreter.
172
172
@@ -203,7 +203,7 @@ Shouldn't that be 100?
203
203
204
204
**Note:** If you're not able to reproduce this, try running the file [mixed_tabs_and_spaces.py](/mixed_tabs_and_spaces.py) via the shell.
205
205
206
-
#### Explanation
206
+
#### 💡 Explanation
207
207
208
208
***Don't mix tabs and spaces!** The character just preceding return is a "tab", and the code is indented by multiple of "4 spaces" elsewhere in the example.
209
209
* This is how Python handles tabs:
@@ -239,7 +239,7 @@ some_dict[5] = "Python"
239
239
240
240
"Python" destroyed the existence of "JavaScript"?
241
241
242
-
#### Explanation
242
+
#### 💡 Explanation
243
243
244
244
*`5` (an `int`type) is implicitly converted to `5.0` (a `float`type) before calculating the hashin Python.
245
245
```py
@@ -297,7 +297,7 @@ for i in x:
297
297
298
298
Yes, it runs for exactly **eight** times and stops.
299
299
300
-
#### Explanation:
300
+
#### 💡 Explanation:
301
301
302
302
* Iteration over a dictionary that you edit at the same time isnot supported.
303
303
* It runs eight times because that's the point at which the dictionary resizes to hold more keys (we have eight deletion entries, so a resize is needed). This is actually an implementation detail.
@@ -379,7 +379,7 @@ Can you guess why the output is `[2, 4]`?
379
379
SyntaxError: EOLwhile scanning string literal
380
380
```
381
381
382
-
#### Explanation
382
+
#### 💡 Explanation
383
383
384
384
- In a raw string literal, as indicated by the prefix `r`, the backslash doesn't have the special meaning.
385
385
- What the interpreter actually does, though, is simply change the behavior of backslashes, so they pass themselves and the following character through. That's why backslashes don't work at the end of a raw string.
- You can read more about [timeit](https://docs.python.org/3/library/timeit.html) from here. It is generally used to measure the execution time of snippets.
432
432
- Don't use `+` for generating long strings — In Python, `str` is immutable, so the left and right strings have to be copied into the new string for every pair of concatenations. If you concatenate four strings of length 10, you'll be copying (10+10) + ((10+10)+10) + (((10+10)+10)+10) =90 characters instead of just 40 characters. Things get quadratically worse as the number and size of the string increases.
433
433
- Therefore, it's advised to use `.format.` or `%` syntax (however, they are slightly slower than `+` for short strings).
@@ -597,7 +597,7 @@ True
597
597
False
598
598
```
599
599
600
-
#### Explanation
600
+
#### 💡 Explanation
601
601
602
602
-`isnot`is a single binary operator, and has behavior different than using `is`and`not` separated.
603
603
-`isnot` evaluates to `False`if the variables on either side of the operator point to the same objectand`True` otherwise.
@@ -635,7 +635,7 @@ Even when the values of `x` were different in every iteration prior to appending
- When defining a function inside a loop that uses the loop variable in its body, the loop function's closure is bound to the variable, not its value. So all of the functions use the latest value assigned to the variable for computation.
641
641
@@ -1267,7 +1267,7 @@ True
1267
1267
```
1268
1268
1269
1269
1270
-
#### Explanation:
1270
+
#### 💡 Explanation:
1271
1271
1272
1272
* Class variables and variables inclass instances are internally handled as dictionaries of a classobject. If a variable name isnot found in the dictionary of the current class, the parent classes are searched for it.
1273
1273
* The `+=` operator modifies the mutable objectin-place without creating a new object. So changing the attribute of one instance affects the other instances and the class attribute as well.
@@ -1306,7 +1306,7 @@ ValueError: list.remove(x): x not in list
1306
1306
SyntaxError: invalid syntax
1307
1307
```
1308
1308
1309
-
#### Explanation
1309
+
#### 💡 Explanation
1310
1310
1311
1311
* To add multiple Exceptions to the except clause, you need to pass them as parenthesized tupleas the first argument. The second argument is an optional name, which when supplied will bind the Exception instance that has been raised. Example,
0 commit comments