250+ TOP MCQs on Sys Module and Answers

Python Multiple Choice Questions on “Sys Module”.

1. Which of the following functions can help us to find the version of python that we are currently working on?
a) sys.version
b) sys.version()
c) sys.version(0)
d) sys.version(1)

Answer: a
Clarification: The function sys.version can help us to find the version of python that we are currently working on. For example, 3.5.2, 2.7.3 etc. this function also returns the current date, time, bits etc along with the version.

2. Which of the following functions is not defined under the sys module?
a) sys.platform
b) sys.path
c) sys.readline
d) sys.argv

Answer: c
Clarification: The functions sys.platform, sys.path and sys.argv are defined under the sys module. The function sys.readline is not defined. However, sys.stdin.readline is defined.

3. The output of the functions len(“abc”) and sys.getsizeof(“abc”) will be the same.
a) True
b) False

Answer: b
Clarification: The function len returns the length of the string passed, and hence it’s output will be 3. The function getsizeof, present under the sys module returns the size of the object passed. It’s output will be a value much larger than 3. Hence the above statement is false.

4. What will be the output of the following Python code, if the code is run on Windows operating system?

import sys
if sys.platform[:2]== 'wi':
	print("Hello")

a) Error
b) Hello
c) No output
d) Junk value

Answer: b
Clarification: The output of the function sys.platform[:2] is equal to ‘wi’, when this code is run on windows operating system. Hence the output printed is ‘hello’.

5. What will be the output of the following Python code, if the sys module has already been imported?

sys.stdout.write("hello world")

a) helloworld
b) hello world10
c) hello world11
d) error

Answer: c
Clarification: The function shown above prints the given string along with the length of the string. Hence the output of the function shown above will be hello world11.

6. What will be the output of the following Python code?

import sys
sys.stdin.readline()

a) ‘n’
b) ‘’
c) ‘10’
d) Error

Answer: a
Clarification: The function shown above works just like raw_input. Hence it automatically adds a ‘n’ character to the input string. Therefore, the output of the function shown above will be: n.

7. What will be the output of the following Python code?

import sys
eval(sys.stdin.readline())
"India"

a) India5
b) India
c) ‘Indian’
d) ‘India’

Answer: d
Clarification: The function shown above evaluates the input into a string. Hence if the input entered is enclosed in double quotes, the output will be enclosed in single quotes. Therefore, the output of this code is ‘India’.

8. What will be the output of the following Python code?

import sys
eval(sys.stdin.readline())
Computer

a) Error
b) ‘Computern’
c) Computer8
d) Computer

Answer: a
Clarification: The code shown above will result in an error. This is because this particular function accepts only strings enclosed in single or double inverted quotes, or numbers. Since the string entered above is not enclosed in single or double inverted quotes, an error will be thrown.

9. What will be the output of the following Python code?

a) Junk value
b) ‘ ‘
c) No output
d) Error

Answer: b
Clarification: The output of the function shown above will be a blank space enclosed in single quotes. Hence the output of the code shown above is ‘ ‘.

10. What will be the output of the following Python code?

import sys
sys.stderr.write(“hello”)

a) ‘hello’
b) ‘hellon’
c) hello
d) hello5

Answer: d
Clarification: The code shown above returns the string, followed by the length of the string. Hence the output of the code shown above is hello5.

11. What will be the output of the following Python code?

a) ‘ ‘
b) [ ]
c) [‘ ‘]
d) Error

Answer: c
Clarification: The output of the code shown above is a blank space inserted in single quotes, which is enclosed by square brackets. Hence the output will be [‘ ‘].

12. To obtain a list of all the functions defined under sys module, which of the following functions can be used?
a) print(sys)
b) print(dir.sys)
c) print(dir[sys])
d) print(dir(sys))

Answer: d
Clarification: The function print(dir(sys)) helps us to obtain a list of all the functions defined under the sys module. The function can be used to obtain the list of functions under any given module in Python.

13. The output of the function len(sys.argv) is ____________
a) Error
b) 1
c) 0
d) Junk value

Answer: b
Clarification: The output of the function sys.argv is [‘ ‘]. When we execute the function len([‘ ‘]), the output is 1. Hence the output of the function len(sys.argv) is also 1.

 

Leave a Reply

Your email address will not be published. Required fields are marked *