GPYC practice question 8 of 15

An operator able to perform bitwise shifts is coded as (select two answers)

Full set: 75 questions
Answer options
A: - -
B: ++
C: << Correct answer
D: >> Correct answer
Correct Answer:
C. ; D. >>
Explanation

In Python, bitwise operators work on integers at the binary level. The <> (right shift) operators are used to perform bitwise shifts. The left shift operator (<>) shifts the bits to the right. These operations are equivalent to multiplication and integer division by powers of two, respectively.

Why Incorrect

A. --: This is not a valid operator in Python. To decrement a variable, one would use the statement x -= 1.
B. ++: This is not a valid operator in Python. To increment a variable, one would use the statement x += 1.

References

1. Python Software Foundation. (2024). The Python Language Reference (Version 3.12.3). Section 6.7, "Shifting Operations". Retrieved from https://docs.python.org/3/reference/expressions.html#shifting-operations. This section explicitly defines <> as the left and right bitwise shift operators.

2. Guttag, J. V. (2016). 6.0001 Introduction to Computer Science and Programming in Python, Fall 2016. Massachusetts Institute of Technology: MIT OpenCourseWare. Lecture 3 Code and Notes, "Operators". The course materials list <> as Python's bitwise shift operators. Retrieved from https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/pages/lecture-3-string-manipulation-guess-and-check-approximations-bisection/

3. Van Rossum, G. (2024). The Python Tutorial (Version 3.12.3). Python Software Foundation. Section 14.1, "Floating Point Arithmetic: Issues and Limitations" (Note). While discussing binary fractions, the tutorial implicitly references the concept of bit shifting as a fundamental operation on binary representations. The main definition resides in the Language Reference.

Scroll to Top