Python regex – r prefix

Because \ begin escape sequences only when they are valid escape sequences. >>> ‘\n’ ‘\n’ >>> r’\n’ ‘\\n’ >>> print ‘\n’ >>> print r’\n’ \n >>> ‘\s’ ‘\\s’ >>> r’\s’ ‘\\s’ >>> print ‘\s’ \s >>> print r’\s’ \s Unless an ‘r’ or ‘R’ prefix is present, escape sequences in strings are interpreted according to … Read more

What’s with the integer cache maintained by the interpreter?

Python caches integers in the range [-5, 256], so integers in that range are usually but not always identical. What you see for 257 is the Python compiler optimizing identical literals when compiled in the same code object. When typing in the Python shell each line is a completely different statement, parsed and compiled separately, … Read more

Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

Per https://docs.python.org/3/reference/lexical_analysis.html#integer-literals: Integer literals are described by the following lexical definitions: integer ::= decimalinteger | octinteger | hexinteger | bininteger decimalinteger ::= nonzerodigit digit* | “0”+ nonzerodigit ::= “1”…”9″ digit ::= “0”…”9″ octinteger ::= “0” (“o” | “O”) octdigit+ hexinteger ::= “0” (“x” | “X”) hexdigit+ bininteger ::= “0” (“b” | “B”) bindigit+ octdigit ::= … Read more

How do I write a short literal in C++?

((short)2) Yeah, it’s not strictly a short literal, more of a casted-int, but the behaviour is the same and I think there isn’t a direct way of doing it. That’s what I’ve been doing because I couldn’t find anything about it. I would guess that the compiler would be smart enough to compile this as … Read more

Setting Short Value Java

In Java, integer literals are of type int by default. For some other types, you may suffix the literal with a case-insensitive letter like L, D, F to specify a long, double, or float, respectively. Note it is common practice to use uppercase letters for better readability. The Java Language Specification does not provide the … Read more

Why write 1,000,000,000 as 1000*1000*1000 in C?

One reason to declare constants in a multiplicative way is to improve readability, while the run-time performance is not affected. Also, to indicate that the writer was thinking in a multiplicative manner about the number. Consider this: double memoryBytes = 1024 * 1024 * 1024; It’s clearly better than: double memoryBytes = 1073741824; as the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)