Concatenate two string literals

const string message = “Hello” + “,world” + exclam; The + operator has left-to-right associativity, so the equivalent parenthesized expression is: const string message = ((“Hello” + “,world”) + exclam); As you can see, the two string literals “Hello” and “,world” are “added” first, hence the error. One of the first two strings being concatenated … Read more

What is the difference between i = i + 1 and i += 1 in a ‘for’ loop? [duplicate]

The difference is that one modifies the data-structure itself (in-place operation) b += 1 while the other just reassigns the variable a = a + 1. Just for completeness: x += y is not always doing an in-place operation, there are (at least) three exceptions: If x doesn’t implement an __iadd__ method then the x … Read more

What does “:=” do?

http://en.wikipedia.org/wiki/Equals_sign#In_computer_programming In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol’s usage in mathematics, or an assignment operator (e.g. as in C-like languages). Languages making the former choice often use a colon-equals (:=) or ≔ … Read more

Asterisk in function call [duplicate]

* is the “splat” operator: It takes an iterable like a list as input, and expands it into actual positional arguments in the function call. So if uniqueCrossTabs were [[1, 2], [3, 4]], then itertools.chain(*uniqueCrossTabs) is the same as saying itertools.chain([1, 2], [3, 4]) This is obviously different from passing in just uniqueCrossTabs. In your … Read more

Why ‘&&’ and not ‘&’?

In most cases, && and || are preferred over & and | because the former are short-circuited, meaning that the evaluation is canceled as soon as the result is clear. Example: if(CanExecute() && CanSave()) { } If CanExecute returns false, the complete expression will be false, regardless of the return value of CanSave. Because of … Read more