Identifier normalization: Why is the micro sign converted into the Greek letter mu?

There are two different characters involved here. One is the MICRO SIGN, which is the one on the keyboard, and the other is GREEK SMALL LETTER MU. To understand what’s going on, we should take a look at how Python defines identifiers in the language reference: identifier ::= xid_start xid_continue* id_start ::= <all characters in … Read more

Why is variable1 += variable2 much faster than variable1 = variable1 + variable2?

This isn’t about using inplace += versus + binary add. You didn’t tell us the whole story. Your original version concatenated 3 strings, not just two: sTable = sTable + ‘\n’ + sRow # simplified, sRow is a function call Python tries to help out and optimises string concatenation; both when using strobj += otherstrobj … Read more

How references to variables are resolved in Python [duplicate]

In an ideal world, you’d be right and some of the inconsistencies you found would be wrong. However, CPython has optimized some scenarios, specifically function locals. These optimizations, together with how the compiler and evaluation loop interact and historical precedent, lead to the confusion. Python translates code to bytecodes, and those are then interpreted by … Read more

Python string literal concatenation

Read the reference manual, it’s in there. Specifically: Multiple adjacent string or bytes literals (delimited by whitespace), possibly using different quoting conventions, are allowed, and their meaning is the same as their concatenation. Thus, “hello” ‘world’ is equivalent to “helloworld”. This feature can be used to reduce the number of backslashes needed, to split long … Read more