Exercise: Python

Questions for: Operators

What is the result of the following expression in Python: 7 != '7'?
A:
True
B:
False
C:
None
D:
Error
Answer: A

The expression 7 != '7' compares the integer value 7 with the string value'7' to check if they are not equal.

In Python, values of different types are considered not equal. Therefore, the result of this expression is True.

Which of the following is an example of a comparison operator?
A:
+
B:
or
C:
and
D:
==
Answer: D

The == operator is a comparison operator in Python, used to check if two values are equal or not.

The other options (+, or, and and) are arithmetic operator, logical operator, and logical operator respectively.

What is the output of the following code snippet?
x = "Hello"
y = "World"
z = x + y
print(z)
A:
Hello World
B:
HelloWorld
C:
Hello + World
D:
Error
Answer: B
The + operator is used to concatenate two strings, which combines the characters of the two strings into a single string.
Which of the following operators is used to perform floor division?
A:
//
B:
%
C:
/
D:
*
Answer: A
The // operator performs floor division, which returns the largest integer value that is less than or equal to the result of the division.
What is the result of the expression 5 == "5"?
A:
True
B:
False
C:
None
D:
Error
Answer: B
The == operator in Python is used to compare the equality of two operands. In this case, the operands are 5 and "5". Although they look similar, they are not equal because one is an integer and the other is a string. Therefore, the result of 5 == "5" is False.
Ad Slot (Above Pagination)
Quiz