All Questions

321
votes
14answers
85671 views

How do I test multiple variables against a value?

I'm trying to make a function that will compare multiple variables to an integer and output a string of three letters. I was wondering if there was a way to translate this into Python. So say: x = 0 ...
106
votes
9answers
16199 views

What are bitwise operators?

I'm someone who writes code just for fun and haven't really delved into it in either an academic or professional setting, so stuff like these bitwise operators really escapes me. I was reading an art...
80
votes
11answers
137918 views

Differences in boolean operators: & vs && and | vs ||

I know the rules for && and || but what are & and |? Please explain these to me with an example.
41
votes
1answers
49249 views

Logic operator for boolean indexing in Pandas

I'm working with boolean index in Pandas. The question is why the statement: a[(a['some_column']==some_number) & (a['some_other_column']==some_other_number)] works fine whereas a[(a['some_colu...
7
votes
4answers
1694 views

Is (4 > y > 1) a valid statement in C++? How do you evaluate it if so?

Is that a valid expression? If so, can you rewrite it so that it makes more sense? For example, is it the same as (4 > y && y > 1)? How do you evaluate chained logical operators?
333
votes
12answers
10446 views

Why does (0 < 5 < 3) return true?

I was playing around in jsfiddle.net and I'm curious as to why this returns true? if(0 < 5 < 3) { alert("True"); } So does this: if(0 < 5 < 2) { alert("True"); } But this doe...
96
votes
4answers
38913 views

How can I obtain the element-wise logical NOT of a pandas Series?

I have a relatively straightforward question, today. I have a pandas Series object containing boolean values. How can I get a series containing the logical NOT of each value? For example, consider a...
542
votes
62answers
134499 views

Check if at least two out of three booleans are true

An interviewer recently asked me this question: given three boolean variables, a, b, and c, return true if at least two out of the three are true. My solution follows: boolean atLeastTwo(boolean a, ...
41
votes
2answers
24166 views

Element-wise logical OR in Pandas

I would like the element-wise logical OR operator. I know "or" itself is not what I am looking for. For AND I want to use & as explained here. For NOT I want to use np.invert() as explained here....
28
votes
6answers
129309 views

How do I test if a variable does not equal either of two values?

I want to write an if/else statement that tests if the value of a text input does NOT equal either one of two different values. Like this (excuse my pseudo-English code): var test = $("#test").val()...

Previous Next