Study and learn Interview MCQ Questions and Answers on Python Byte Code basics. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.
Go through Python Theory Notes on Compiling Running and Python Theory Notes on Byte Code before reading these objective questions.
1) What is the file name extension of a Python Program?
A) .PY
B) .PYC
C) .PYB
D) .PYBY
A
Explanation: A python program can have .PY as the file name extension.
2) What is the file name extension of a Python Byte Code file?
A) .PYB
B) .PYC
C) .PYBY
D) .PYB
C
Explanation: .PYC is the file extension of a byte code file generated.
3) What is the size of a single byte code instruction in Python?
A) 1 KB
B) 1 Byte
C) 4 Bits
D) 1024 Bytes
B
Explanation: As a single python byte code instructions takes 1 Byte of storage, it is called Byte Code.
4) Which is the module used to generate Python Bytecode from source code?
A) py_bytecode
B) py_compile
C) pyparse
D) pyshell
B
Explanation: py_compile module enables you to generate Bytecode from the source file.
5) py_compile is a ______ module.
A) Built-in module
B) Third party module
C) --
D) --
A
6) Which is the command used to generate Python Byte code?
A) py_compile
B) python
C) pydoc
D) pyshell
B
Explanation: The same "PYTHON" command allows you to compile, generate byte code and run a Python program?
7) Where can you locate Python Byte Code files?
A) Inside the same directory
B) __pycache__ directory of the program's directory
C) C:\Program Files>
D) C:\Windows
B
Explanation: Python creates a directory where ever the Python program is located with the name __pycache__. Just navigate to that directory to find Byte Code files.
8) What is the file name convention of generated Byte Code file?
A) PROGRAM_NAME.PYC
B) PRGRAM_NAME_PYTHON_VERSION.PYC
C) PROGRAM_NAME.CPYTHON-PYTHON_VERSION.PYC
D) PROGRAM_NAME.CPYTHON.PYC
C
Explanation:
Two things are appended to the original python program i.e CPYTHON and PYTHON_VERSION.
hello.cpython-311.pyc
9) Which is the module used to view Python Byte code?
A) py_compile
B) python
C) dis
D) opcode
C
Explanation: DIS module allows you to view byte code of a python program.
10) What is a DIS module in python?
A) Disassembler
B) display
C) discloser
D) None of the above
A
Explanation: Disassembler module dis-assembles a byte code file for viewing. It shows byte code instructions.
11) Identify byte code instructions below?
A) LOAD_NAME
B) LOAD_CONST
C) CALL_FUNCTION
D) All the above
D
12) Identify Byte Code instructions below.
A) POP_TOP
B) CALL_FUNCTION
C) RETURN_VALUE
D) All the above
D
13) Choose a Byte Code instruction file below.
A)
0 0 RESUME 0 1 2 LOAD_CONST 0 (5) 4 STORE_NAME 0 (a) 6 LOAD_CONST 1 (10) 8 STORE_NAME 1 (b) 2 10 PUSH_NULL 12 LOAD_NAME 2 (print) 14 LOAD_NAME 0 (a) 16 LOAD_NAME 1 (b) 18 BINARY_OP 0 (+) 22 PRECALL 1 26 CALL 1 36 POP_TOP 38 LOAD_CONST 2 (None) 40 RETURN_VALUE
B)
0 0 RESUME 0 1 2 PUSH_NULL 4 LOAD_NAME 0 (print) 6 LOAD_CONST 0 ('This is to say hi..!') 8 PRECALL 1 12 CALL 1 22 POP_TOP 24 LOAD_CONST 1 (None) 26 RETURN_VALUE
C)
0 0 RESUME 0 1 2 LOAD_CONST 0 (2) 4 STORE_NAME 0 (a) 2 6 LOAD_NAME 0 (a) 8 LOAD_CONST 1 (0) 10 COMPARE_OP 4 (>) 16 POP_JUMP_FORWARD_IF_FALSE 24 (to 66) 3 >> 18 PUSH_NULL 20 LOAD_NAME 1 (print) 22 LOAD_NAME 0 (a) 24 PRECALL 1 28 CALL 1 38 POP_TOP 4 40 LOAD_NAME 0 (a) 42 LOAD_CONST 2 (1) 44 BINARY_OP 10 (-) 48 STORE_NAME 0 (a) 2 50 LOAD_NAME 0 (a) 52 LOAD_CONST 1 (0) 54 COMPARE_OP 4 (>) 60 POP_JUMP_BACKWARD_IF_TRUE 22 (to 18) 62 LOAD_CONST 3 (None) 64 RETURN_VALUE >> 66 LOAD_CONST 3 (None) 68 RETURN_VALUE
D) All the above
D
Prev Chapter Link