Boolean Values, Conditional Execution, Loops, Lists and List Processing, Logical and Bitwise Operations Flashcards
What is the difference between = and ==?
= is an assignment operator (assign value to variables)
== is the equality operator (binary operator with left sided binding)
2 == 2.0
True
True or false: comparison operators have higher priority than equality operators
True
What is an if statement known as?
Condition statement/instruction
What is an if statement within an if statement called?
Nested if statement
Explain the difference between if and while
When the condition is met:
- if performs its statements only once
- while repeats the execution as long as the condition evaluates to True
What is an endless loop?
An infinite loop is a sequence of instructions in a program which repeat indefinitely
What is ‘while number:’ equivalent to?
while number != 0:
What is used to exit the loop immediately?
break
What is continue used for?
behaves as if the program has suddenly reached the end of the body; the next turn is started and the condition expression is tested immediately.
What are the two types of loops in python?
for and while
What is and?
a conjunction
(binary operator with lower priority than comparison operators)
What is or?
a disjunction
(binary operator with lower priority than and)
What are logical operators?
AND and OR
What is the unary operator performing a logical negation?
NOT
(same priority are unary +/- (v high))
What are the four bitwise operators?
& (ampersand) - bitwise conjunction;
(bar) - bitwise disjunction
~ (tilde) - bitwise negation;
^ (caret) - bitwise exclusive or (xor)
(bar) - bitwise disjunction
What do bitwise operators allow you to do?
allow you to manipulate single bits of data
True or False:
The arguments for bitwise operators must be integers
True
cannot use floats
What is the difference in the operation of the logical and bit operators?
the logical operators do not penetrate into the bit level of its argument. They’re only interested in the final integer value.
Bitwise operators are stricter: they deal with every bit separately.
What is a bit mask?
a sequence of zeros and ones, whose task is to grab the value or to change the selected bits
What is shifting a value one bit to the left equivalent to?
Multiplying by 2 as 2 is the base for binary numbers
What are the shift operators?
«_space;and»_space;
The left argument of these operators is an integer value whose bits are shifted. The right argument determines the size of the shift.
What does 17»_space; 1 equal?
17 // 2 (17 floor-divided by 2 to the power of 1) → 8
What does 17 «_space;2 equal?
17 * 4 (17 multiplied by 2 to the power of 2) → 68