Python Programming - Operators

Exercise : Operators - General Questions
  • Operators - General Questions
6.
Which operator is used for concatenating two strings?
+
~
.
|
Answer: Option
Explanation:
The + operator in Python is used for concatenating two strings. For example, "Hello " + "World" will result in "Hello World".

7.
Which operator is used for performing Bitwise AND operation?
&&
&
||
|
Answer: Option
Explanation:
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.

8.
What is the output of the following code?
num1 = 10
num2 = 20
num3 = 30
result = num1 < num2 and num3 > num2

print(result)
True
False
None
Error
Answer: Option
Explanation:
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.

9.
Which bitwise operator is used for the "exclusive or" (XOR)?
and
or
not
^
Answer: Option
Explanation:

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
====================

10.
What is the output of the following code?
x = True
y = False
result = not x or y

print(result)
True
False
None
Error
Answer: Option
Explanation:
The not operator is used to negate the value of a boolean expression. In the code, not x means not True, which is False. The or operator returns True if at least one of the expressions is True. So, the expression not x or y becomes False or False, which evaluates to False.