What does 'x, y =' mean in python syntax?
At least, as of python 2.7.x, the function will unpack a tuple of 2 arguments returned from a function. If it returns anything other than 2 arguments in the tuple, I believe it will throw an error if you try to unpack more than this. If it returns 3 arguments and you unpack 2, for example, you will get an exception.
For example:
def func(a):
return (a,a+1,a*2)
a,b,c = func(7)
print a,b
==> 7 8 # NOTE Values
a = func(3)
print a
==> (3, 4, 6) # NOTE: TUPLE
a,b = func(9)
print a,b
==> Exception - ValueError: too many values to unpack
This may be different in 3.0+.
Simplify Boolean Expression: X + X'Y'Z
Expression Justification
--------------------------------- -------------------------
X + X'Y'Z initial expression
(XY'Z + X(Y'Z)') + X'Y'Z r = rs + rs'
(XY'Z + XY'Z + X(Y'Z)') + X'Y'Z r = r + r
(XY'Z + X(Y'Z)' + XY'Z) + X'Y'Z r + s = s + r
(XY'Z + X(Y'Z)') + (XY'Z + X'Y'Z) (r + s) + t = r + (s + t)
X(Y'Z + (Y'Z)') + (Y'Z)(X + X') rs + rt = r(s + t)
X(1) + (Y'Z)(1) r + r' = 1
X + Y'Z r(1) = r
Difference between (X != Y) and (!(X == Y))?
!(x == y)
and x != y
are logically equivalent and I doubt any language, compiled or interpreted, would evaluate them differently internally. In other words, I'd be surprised if you found a measurable difference.
Some languages such as C++ and Scala lets you override these operators, in which case it's a different story of course.
What does the construct x = x || y mean?
It means the title
argument is optional. So if you call the method with no arguments it will use a default value of "Error"
.
It's shorthand for writing:
if (!title) {
title = "Error";
}
This kind of shorthand trick with boolean expressions is common in Perl too. With the expression:
a OR b
it evaluates to true
if either a
or b
is true
. So if a
is true you don't need to check b
at all. This is called short-circuit boolean evaluation so:
var title = title || "Error";
basically checks if title
evaluates to false
. If it does, it "returns" "Error"
, otherwise it returns title
.
Related Topics
Why Do Un-Named C++ Objects Destruct Before the Scope Block Ends
Why Is It Not Good to Use Recursive Inheritance for Std::Tuple Implementations
Vector of Std::Function with Different Signatures
C++ How to Generate All the Permutations of Function Overloads
Complete C++ I18N Gettext() "Hello World" Example
How to Alloc a Executable Memory Buffer
Correctly Reading a Utf-16 Text File into a String Without External Libraries
In C++, How to Forward Declare a Class as Inheriting from Another Class
Is There a Portable Equivalent to Debugbreak()/_Debugbreak
Std::Put_Time Implementation Status in Gcc
Easiest Way to Rotate by 90 Degrees an Image Using Opencv
Does Casting to an Int After Std::Floor Guarantee the Right Result
How to Replace All Instances of a String with Another String