Exercise: Python

Questions for: Operators

Which bitwise operator is used for the "exclusive or" (XOR)?
A:
and
B:
or
C:
not
D:
^
Answer: D

The ^ operator compares each bit and set it to 1 if only one is 1, otherwise (if both are 1 or both are 0) it is set to 0:

For example:

7 = 0000000000000111
3 = 0000000000000011
--------------------
4 = 0000000000000100
====================
What is the output of the following code?
num1 = 10
num2 = 20
num3 = 30
result = num1 < num2 and num3 > num2

print(result)
A:
True
B:
False
C:
None
D:
Error
Answer: A
In the code, the logical operator and is used to combine two conditions. The first condition num1 < num2 is True, and the second condition num3 > num2 is also True. So, the overall result is True.
Which operator is used for performing Bitwise AND operation?
A:
&&
B:
&
C:
||
D:
|
Answer: B
The & operator in Python is used for performing Bitwise AND operation on two operands. For example, 0110 & 0011 will result in 0010 as the output.
Which operator is used for concatenating two strings?
A:
+
B:
~
C:
.
D:
|
Answer: A
The + operator in Python is used for concatenating two strings. For example, "Hello " + "World" will result in "Hello World".
What is the result of the following operation: not (3 < 5)?
A:
True
B:
False
C:
Error
D:
None
Answer: B
The not operator is a logical operator that returns the opposite of a Boolean value. In this case, the expression (3 < 5) is True, but the not operator negates it to False.
Ad Slot (Above Pagination)
Quiz