Python MCQ’s on Modules: SET 11

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

import sys

sys.stderr.write(“hello”)

a) ‘hello’

b) ‘hello\n’

c) hello

d) hello5

Check Answer

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

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

import sys

sys.argv

a) ‘ ‘

b) [ ]

c) [‘ ‘]

d) Error

Check Answer

Answer: c
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 [‘ ‘].

103. 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))

Check Answer

Answer: d
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.

104. The output of the function len(sys.argv) is ____________

a) Error

b) 1

c) 0

d) Junk value

Check Answer

Answer: b
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.

105. What does os.name contain?

a) the name of the operating system dependent module imported

b) the address of the module os

c) error, it should’ve been os.name()

d) none of the mentioned

Check Answer

Answer: a
It contains the name of the operating system dependent module imported such as ‘posix’, ‘java’ etc.

106. What does print(os.geteuid()) print?

a) the group id of the current process

b) the user id of the current process

c) both the group id and the user of the current process

d) none of the mentioned

Check Answer

Answer: b
os.geteuid() gives the user id while the os.getegid() gives the group id.

107. What does os.getlogin() return?

a) name of the current user logged in

b) name of the superuser

c) gets a form to login as a different user

d) all of the mentioned

Check Answer

Answer: a
It returns the name of the user who is currently logged in and is running the script.

108. What does os.close(f) do?

a) terminate the process f

b) terminate the process f if f is not responding

c) close the file descriptor f

d) return an integer telling how close the file pointer is to the end of file

Check Answer

Answer: c
When a file descriptor is passed as an argument to os.close() it will be closed.

109. What does os.fchmod(fd, mode) do?

a) change permission bits of the file

b) change permission bits of the directory

c) change permission bits of either the file or the directory

d) none of the mentioned

Check Answer

Answer: a
The arguments to the function are a file descriptor and the new mode.

110. Which of the following functions can be used to read data from a file using a file descriptor?

a) os.reader()

b) os.read()

c) os.quick_read()

d) os.scan()

Check Answer

Answer: b
None of the other functions exist.

Page  1  2  3  4  5  6  7  8  9  10  11  12  13  14    15  16 

Leave a Comment