Podcast
Questions and Answers
What is the output type of the input() function, regardless of the input given?
What is the output type of the input() function, regardless of the input given?
The floor division operator (//) returns a float type result.
The floor division operator (//) returns a float type result.
False
What is the result of the expression 5 ** 2?
What is the result of the expression 5 ** 2?
25
The operator '==' checks if two values are ______.
The operator '==' checks if two values are ______.
Signup and view all the answers
Match the following operators with their functions:
Match the following operators with their functions:
Signup and view all the answers
What will be the output of the expression 7 % 3?
What will be the output of the expression 7 % 3?
Signup and view all the answers
The operator 'not' returns True if the input is True.
The operator 'not' returns True if the input is True.
Signup and view all the answers
What does the bitwise AND operator (&) do?
What does the bitwise AND operator (&) do?
Signup and view all the answers
What is the result of the expression a ^ b
given that a = 5
(0101 in binary) and b = 3
(0011 in binary)?
What is the result of the expression a ^ b
given that a = 5
(0101 in binary) and b = 3
(0011 in binary)?
Signup and view all the answers
The bitwise OR operation will result in 1 only if both input bits are 0.
The bitwise OR operation will result in 1 only if both input bits are 0.
Signup and view all the answers
What does the bitwise negation operator (~) do to a bit?
What does the bitwise negation operator (~) do to a bit?
Signup and view all the answers
The operator used to check if a value is not present in a data structure is called __________.
The operator used to check if a value is not present in a data structure is called __________.
Signup and view all the answers
Which of the following expressions would produce a 'True' result when evaluating x is y
?
Which of the following expressions would produce a 'True' result when evaluating x is y
?
Signup and view all the answers
The expression '1 in [1, 2, 3]' returns false.
The expression '1 in [1, 2, 3]' returns false.
Signup and view all the answers
Describe operator precedence in Python.
Describe operator precedence in Python.
Signup and view all the answers
Match the following operators with their descriptions:
Match the following operators with their descriptions:
Signup and view all the answers
The expression 'x >> n' performs a __________ right shift operation.
The expression 'x >> n' performs a __________ right shift operation.
Signup and view all the answers
Study Notes
Input Function
- The
input()
function takes user input as a string. - The input is always a string, even if the user enters a number.
Arithmetic Operators
-
+
(Unary Positive): Used to indicate a positive value; has no effect on the operand. -
+
(Binary Addition): Adds two operands together. -
-
(Unary Negation): Changes the sign of the operand (makes it negative). -
-
(Binary Subtraction): Subtracts the second operand from the first. -
*
(Multiplication): Multiplies two operands. -
/
(Division): Divides the first operand by the second. The result is always a float. -
%
(Modulo): Returns the remainder of a division. -
//
(Floor Division): Performs division and rounds the result down to the nearest integer. -
**
(Exponentiation): Raises the first operand to the power of the second.
Comparison Operators
-
==
(Equal to): Checks if two operands are equal; returnsTrue
if they are,False
otherwise. -
!=
(Not Equal to): Checks if two operands are not equal; returnsTrue
if they are not equal,False
otherwise. -
<
(Less than): Checks if the first operand is less than the second; returnsTrue
if it is,False
otherwise. -
>
(Greater than): Checks if the first operand is greater than the second; returnsTrue
if it is,False
otherwise. -
<=
(Less than or equal to): Checks if the first operand is less than or equal to the second; returnsTrue
if it is,False
otherwise. -
>=
(Greater than or equal to): Checks if the first operand is greater than or equal to the second; returnsTrue
if it is,False
otherwise.
Logical Operators
-
not
(Logical Negation): Inverts the truth value of an operand; returnsTrue
if the operand isFalse
, andFalse
if the operand isTrue
. -
or
(Logical OR): ReturnsTrue
if at least one of the operands isTrue
,False
otherwise. -
and
(Logical AND): ReturnsTrue
if both operands areTrue
,False
otherwise.
Bitwise Operators
-
&
(Bitwise AND): Performs a bitwise AND operation on each corresponding bit of the operands; returns 1 if both bits are 1, 0 otherwise. -
|
(Bitwise OR): Performs a bitwise OR operation on each corresponding bit of the operands; returns 1 if at least one bit is 1, 0 otherwise. -
~
(Bitwise Negation): Flips the bits of an operand (0 becomes 1, 1 becomes 0). -
^
(Bitwise XOR): Performs a bitwise XOR operation on each corresponding bit of the operands; returns 1 if the bits are different, 0 if they are the same. -
>>
(Right Shift): Shifts all bits in the first operand to the right by the number of positions specified by the second operand.
Membership Operators
-
in
: Checks if a value exists within another data structure (string, list, tuple, dictionary). ReturnsTrue
if it exists,False
otherwise. -
not in
: Checks if a value doesn't exist within another data structure. ReturnsTrue
if it doesn't exist,False
otherwise.
Operator Precedence
- Operator precedence determines the order in which operators are evaluated within an expression.
- Operators with higher precedence are evaluated before operators with lower precedence.
- Parentheses can be used to override precedence.
Augmented Assignment Operators
- Augmented assignment operators combine an arithmetic or bitwise operation with an assignment in one step.
- For example,
x += 5
is equivalent tox = x + 5
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Explore the fundamental arithmetic and comparison operators in Python through this quiz. Learn how to use operators like addition, subtraction, and comparison to manipulate data and evaluate expressions. Test your knowledge and deepen your understanding of Python syntax and functionality.