How to include a double-quote and/or single-quote character in a raw Python string literal?

If you want to use double quotes in strings but not single quotes, you can just use single quotes as the delimiter instead: r’what”ever’ If you need both kinds of quotes in your string, use a triple-quoted string: r”””what”ev’er””” If you want to include both kinds of triple-quoted strings in your string (an extremely unlikely … Read more

Is there a difference between “pass” and “continue” in a for loop in Python?

Yes, they do completely different things. pass simply does nothing, while continue goes on with the next loop iteration. In your example, the difference would become apparent if you added another statement after the if: After executing pass, this further statement would be executed. After continue, it wouldn’t. >>> a = [0, 1, 2] >>> … Read more

Why is this Java code in curly braces ({}) outside of a method?

Borrowed from here – Normally, you would put code to initialize an instance variable in a constructor. There are two alternatives to using a constructor to initialize instance variables: initializer blocks and final methods. Initializer blocks for instance variables look just like static initializer blocks, but without the static keyword: { // whatever code is … Read more

C# binary literals

Update C# 7.0 now has binary literals, which is awesome. [Flags] enum Days { None = 0, Sunday = 0b0000001, Monday = 0b0000010, // 2 Tuesday = 0b0000100, // 4 Wednesday = 0b0001000, // 8 Thursday = 0b0010000, // 16 Friday = 0b0100000, // etc. Saturday = 0b1000000, Weekend = Saturday | Sunday, Weekdays = … Read more

Create an incrementing variable from 2 variables in PowerShell

You’re looking for variable indirection, i.e. the ability to refer to a variable indirectly, by a name stored in another variable or returned from an expression. Note, however, that there are usually superior alternatives, such as using arrays or hashtables as multi-value containers – see this answer for an example. If you do need to … Read more

“Unknown escape sequence” error in Go

The \ backslash isn’t being interpreted by the regex parser, it’s being interpreted in the string literal. You should escape the backslash again: regexp.Compile(“[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+”) A string quoted with ” double-quote characters is known as an “interpreted string literal” in Go. Interpreted string literals are like string literals in most languages: \ backslash characters aren’t included … Read more