Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

The copy module uses the ___________________ protocol for shallow and deep copy.(a) pickle(b) marshal(c) shelve(d) copyregThe question was posed to me in quiz.The origin of the question is Pickle Module in division Mapping Functions and Modules of Python

Answer»

The correct answer is (a) pickle

The best I can EXPLAIN: The COPY module USES the pickle PROTOCOL for SHALLOW and deep copy.

2.

The module _______________ is a comparatively faster implementation of the pickle module.(a) cPickle(b) nPickle(c) gPickle(d) tPickleThe question was asked in class test.I want to ask this question from Pickle Module topic in division Mapping Functions and Modules of Python

Answer»

The CORRECT option is (a) CPICKLE

Easy explanation - The module cPickle is a COMPARATIVELY FASTER implementation of the PICKLE module.

3.

Lambda functions cannot be pickled because:(a) Lambda functions only deal with binary values, that is, 0 and 1(b) Lambda functions cannot be called directly(c) Lambda functions cannot be identified by the functions of the pickle module(d) All lambda functions have the same name, that is, I got this question in an online quiz.My query is from Pickle Module topic in portion Mapping Functions and Modules of Python

Answer» CORRECT CHOICE is (d) All lambda functions have the same name, that is,

The EXPLANATION: Lambda functions cannot be PICKLED because all the lambda functions have the same name, that is,
4.

If __getstate__() returns _______________ the __setstate__() module will not be called on pickling.(a) True value(b) False value(c) ValueError(d) OverflowErrorThis question was addressed to me by my college professor while I was bunking the class.Query is from Pickle Module in portion Mapping Functions and Modules of Python

Answer»

The correct option is (b) False value

Easiest EXPLANATION - If getstate__() returns a false value, the __setstate__()module will not be CALLED on pickling.

5.

Which of the following cannot be pickled?(a) Functions which are defined at the top level of a module with lambda(b) Functions which are defined at the top level of a module with def(c) Built-in functions which are defined at the top level of a module(d) Classes which are defined at the top level of a moduleThe question was asked in an online interview.I'm obligated to ask this question of Pickle Module in division Mapping Functions and Modules of Python

Answer»

The correct option is (a) Functions which are defined at the top LEVEL of a MODULE with LAMBDA

To explain: Functions which are defined at the top level of a module with lambda cannot be PICKLED.

6.

The pickle module defines ______ exceptions and exports _______ classes.(a) 2, 3(b) 3, 4(c) 3, 2(d) 4, 3I had been asked this question in an interview.My doubt stems from Pickle Module topic in chapter Mapping Functions and Modules of Python

Answer»

The correct option is (C) 3, 2

The best I can EXPLAIN: The pickle module defines three exceptions, namely, pickle.PickleError, pickle.PicklingError, pickle.UnpickleError and EXPORTS two classes, namely, pickle.Pickler and pickle.Unpickler.

7.

Which of the following functions raises an error when an unpicklable object is encountered by Pickler?(a) pickle.PickleError(b) pickle.PicklingError(c) pickle.UnpickleError(d) pickle.UnpicklingErrorThe question was asked in final exam.I want to ask this question from Pickle Module topic in portion Mapping Functions and Modules of Python

Answer»

Correct CHOICE is (b) pickle.PicklingError

Explanation: The FUNCTION pickle.PicklingError RAISES an ERROR when an unpickable object is encountered by Pickler.

8.

Which of the following functions can accept more than one positional argument?(a) pickle.dumps(b) pickle.loads(c) pickle.dump(d) pickle.loadThe question was asked in final exam.My enquiry is from Pickle Module in portion Mapping Functions and Modules of Python

Answer» RIGHT answer is (a) pickle.dumps

Best explanation: The functions pickle.loads, pickle.dump and pickle.load ACCEPT only ONE argument. The FUNCTION pickle.dumps can accept more than one argument.
9.

Which of the following functions can be used to find the protocol version of the pickle module currently being used?(a) pickle.DEFAULT(b) pickle.CURRENT(c) pickle.CURRENT_PROTOCOL(d) pickle.DEFAULT_PROTOCOLThis question was addressed to me during an internship interview.The above asked question is from Pickle Module topic in chapter Mapping Functions and Modules of Python

Answer»

Correct ANSWER is (d) PICKLE.DEFAULT_PROTOCOL

The explanation is: The FUNCTION pickle.DEFAULT_PROTOCOL can be used to find the protocol version of the pickle MODULE currently being used by the system.

10.

Pick the correct statement regarding pickle and marshal modules.(a) The pickle module supports primarily .pyc files whereas marshal module is used to sterilize Python objects(b) The pickle module keeps track of the objects that have already been sterilized whereas the marshal module does not do this(c) The pickle module cannot be used to sterilize user defined classes and their instances whereas marshal module can be used to perform this task(d) The format of sterilization of the pickle module is not guaranteed to be supported across all versions of Python. The marshal module sterilization is compatible across all the versions of PythonThe question was posed to me in my homework.My doubt stems from Pickle Module in section Mapping Functions and Modules of Python

Answer»

The CORRECT choice is (b) The pickle module KEEPS track of the objects that have already been sterilized whereas the marshal module does not do this

To explain I would say: The correct statement from among the above options is that the python module keeps track of the objects that have already been sterilized whereas the marshal module does not do this. The rest of the STATEMENTS are incorrect.

11.

To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.(a) dumps(), undumps()(b) loads(), unloads()(c) loads(), dumps()(d) dumps(), loads()The question was posed to me in an online interview.My question is from Pickle Module topic in section Mapping Functions and Modules of Python

Answer»

Right option is (d) dumps(), LOADS()

Easy explanation - To STERILIZE an object HIERARCHY, the dumps() FUNCTION must be called. To desterilize a data STREAM, the loads function must be called.

12.

The process of pickling in Python includes:(a) conversion of a list into a datatable(b) conversion of a byte stream into Python object hierarchy(c) conversion of a Python object hierarchy into byte stream(d) conversion of a datatable into a listI have been asked this question by my school teacher while I was bunking the class.This intriguing question comes from Pickle Module topic in section Mapping Functions and Modules of Python

Answer» RIGHT choice is (c) conversion of a Python object HIERARCHY into byte stream

Easy explanation - Pickling is the PROCESS of sterilizing a Python object, that is, conversion of a byte stream into Python object hierarchy. The reverse of this process is known as UNPICKLING.
13.

The function used to alter the thickness of the pen to ‘x’ units:(a) turtle.width(x)(b) turtle.span(x)(c) turtle.girth(x)(d) turtle.thickness(x)This question was addressed to me in an online quiz.The question is from Turtle Module topic in section Mapping Functions and Modules of Python

Answer»

Right CHOICE is (a) turtle.width(X)

EXPLANATION: The function turtle.width(x) is used to alter the thickness of the pen to ‘x’ UNITS. The function turtle.span(x), turtle.girth(x) and turtle.thickness(x) are invalid.

14.

Which of the following functions results in an error?(a) turtle.shape(“turtle”)(b) turtle.shape(“square”)(c) turtle.shape(“triangle”)(d) turtle.shape(“rectangle”)The question was posed to me in my homework.Question is from Turtle Module in division Mapping Functions and Modules of Python

Answer»

The CORRECT choice is (d) turtle.shape(“RECTANGLE”)

Easy EXPLANATION - The functions shown above will change the ARROW to the shape mentioned. The functions turtle.shape(“turtle”), turtle.shape(“square”) and turtle.shape(“TRIANGLE”) are valid whereas the function turtle.shape(“rectangle”) is invalid.

15.

Which of the following functions returns a value in degrees, counterclockwise from the horizontal right?(a) heading()(b) degrees()(c) position()(d) window_height()I got this question in an interview.This interesting question is from Turtle Module in chapter Mapping Functions and Modules of Python

Answer»

The correct choice is (a) heading()

Explanation: The function heading() RETURNS the heading of the turtle, which is a VALUE in DEGREES counterclockwise from the HORIZONTAL right. This measure will be in RADIANS if radians() has been called.

16.

The command used to set only the x coordinate of the turtle at 45 units is:(a) reset(45)(b) setx(45)(c) xset(45)(d) xreset(45)The question was posed to me during an online interview.Question is from Turtle Module in chapter Mapping Functions and Modules of Python

Answer»

The correct CHOICE is (b) setx(45)

EXPLANATION: The COMMAND setx(45) is used to set the x coordinate of the turtle. Similarly, the command sety() is used to set the y coordinate of the turtle. The function RESET() TAKES two values as arguments, one for the x-coordinate and the other for the y-coordinate.

17.

In which direction is the turtle pointed by default?(a) North(b) South(c) East(d) WestThis question was addressed to me in an online quiz.This interesting question is from Turtle Module in section Mapping Functions and Modules of Python

Answer»

Right option is (c) East

For EXPLANATION: By default, the turtle is pointed TOWARDS the east direction. We can CHANGE the direction of the turtle by using certain commands. However, whenever the turtle is reset, it POINTS towards east.

18.

Which of the following functions can be used to make the arrow black?(a) turtle.color(0,1,0)(b) turtle.color(1,0,0)(c) turtle.color(0,0,1)(d) turtle.color(0,0,0)The question was asked in an online interview.The above asked question is from Turtle Module in division Mapping Functions and Modules of Python

Answer»

Right choice is (d) turtle.color(0,0,0)

Explanation: The FUNCTION turtle.color(0,0,0) can CHANGE the colour of the arrow. The function turtle.color(0,1,0) will make the arrow green. The function turtle.color(1,0,0) will make the arrow red. The function turtle.color(0,0,1) will make the arrow BLUE. The function turtle.color(0,0,0) will make the arrow BLACK.

19.

Which of the following functions does not accept any arguments?(a) position(b) fillcolor(c) goto(d) setheading()The question was asked in an online quiz.Question is from Turtle Module topic in section Mapping Functions and Modules of Python

Answer»

Correct OPTION is (a) POSITION

Best EXPLANATION: The FUNCTIONS fillcolor(), goto() and setheading() accept arguments, whereas the function position() does not accept any arguments. The function position() returns the current position of the turtle.

20.

The command which helps us to reset the pen (turtle):(a) turtle.reset(b) turtle.penreset(c) turtle.penreset()(d) turtle.reset()I have been asked this question in an online quiz.The doubt is from Turtle Module topic in portion Mapping Functions and Modules of Python

Answer»

Correct choice is (d) turtle.RESET()

BEST explanation: The command turtle.reset() helps us to reset the pen. After the execution of this command, we get a BLANK PAGE with an arrow on it. We can then perform any desired operation on this page.

21.

Which of the following can be used to create a symbolic link?(a) os.symlink()(b) os.symb_link()(c) os.symblin()(d) os.ln()This question was addressed to me in an interview for job.Asked question is from Operating System in division Mapping Functions and Modules of Python

Answer»

Correct ANSWER is (a) os.symlink()

For explanation: It is the FUNCTION that ALLOWS you to create a SYMBOLIC link.

22.

Which of the following can be used to create a directory?(a) os.mkdir()(b) os.creat_dir()(c) os.create_dir()(d) os.make_dir()This question was posed to me at a job interview.My question is from Operating System in chapter Mapping Functions and Modules of Python

Answer»

Right CHOICE is (a) os.MKDIR()

EXPLANATION: The FUNCTION mkdir() creates a directory in the path specified.

23.

What does os.link() do?(a) create a symbolic link(b) create a hard link(c) create a soft link(d) none of the mentionedThis question was addressed to me in semester exam.My query is from Operating System topic in portion Mapping Functions and Modules of Python

Answer»

The correct answer is (B) CREATE a HARD link

The BEST I can explain: os.link(source, destination) will create a hard link from source to destination.

24.

Which of the following returns a string that represents the present working directory?(a) os.getcwd()(b) os.cwd()(c) os.getpwd()(d) os.pwd()The question was asked at a job interview.This interesting question is from Operating System topic in chapter Mapping Functions and Modules of Python

Answer» CORRECT answer is (a) os.getcwd()

The explanation is: The function getcwd() (get CURRENT working DIRECTORY) returns a STRING that represents the PRESENT working directory.
25.

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()The question was asked at a job interview.The query is from Operating System topic in division Mapping Functions and Modules of Python

Answer»

The CORRECT choice is (b) os.read()

For explanation: NONE of the other functions EXIST.

26.

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 mentionedThe question was asked in semester exam.The above asked question is from Operating System topic in section Mapping Functions and Modules of Python

Answer» CORRECT option is (a) change PERMISSION bits of the FILE

The BEST explanation: The arguments to the function are a file DESCRIPTOR and the new mode.
27.

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 fileThe question was asked during an interview.My enquiry is from Operating System topic in portion Mapping Functions and Modules of Python

Answer»

The correct OPTION is (C) CLOSE the file descriptor f

Easiest explanation - When a file descriptor is PASSED as an argument to os.close() it will be CLOSED.

28.

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 mentionedI have been asked this question by my school teacher while I was bunking the class.I'd like to ask this question from Operating System in section Mapping Functions and Modules of Python

Answer»

The CORRECT CHOICE is (a) name of the current user LOGGED in

Explanation: It returns the name of the user who is CURRENTLY logged in and is running the script.

29.

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 mentionedThis question was addressed to me in an online quiz.My enquiry is from Operating System in section Mapping Functions and Modules of Python

Answer»

The CORRECT OPTION is (B) the user ID of the current process

Explanation: os.geteuid() GIVES the user id while the os.getegid() gives the group id.

30.

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 mentionedI have been asked this question during an internship interview.This key question is from Operating System topic in chapter Mapping Functions and Modules of Python

Answer»

Correct answer is (a) the name of the operating system dependent MODULE IMPORTED

Explanation: It CONTAINS the name of the operating system dependent module imported such as ‘posix’, ‘JAVA’ etc.

31.

The output of the function len(sys.argv) is ____________(a) Error(b) 1(c) 0(d) Junk valueI had been asked this question by my school teacher while I was bunking the class.Origin of the question is Sys Module in chapter Mapping Functions and Modules of Python

Answer»

The CORRECT OPTION is (b) 1

Explanation: 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.

32.

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))I got this question in a national level competition.This intriguing question comes from Sys Module topic in division Mapping Functions and Modules of Python

Answer»

Right option is (d) print(DIR(sys))

Easy EXPLANATION - 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.

33.

The output of the functions len(“abc”) and sys.getsizeof(“abc”) will be the same.(a) True(b) FalseThis question was posed to me in an interview.The origin of the question is Sys Module topic in section Mapping Functions and Modules of Python

Answer» CORRECT choice is (B) False

Best explanation: 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.
34.

Which of the following functions is not defined under the sys module?(a) sys.platform(b) sys.path(c) sys.readline(d) sys.argvI got this question during an online exam.This key question is from Sys Module in portion Mapping Functions and Modules of Python

Answer»

Correct ANSWER is (C) SYS.readline

The explanation is: 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.

35.

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)This question was posed to me in homework.My enquiry is from Sys Module in section Mapping Functions and Modules of Python

Answer»

The correct answer is (a) sys.VERSION

Explanation: 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.

36.

What is the range of values that random.random() can return?(a) [0.0, 1.0](b) (0.0, 1.0](c) (0.0, 1.0)(d) [0.0, 1.0)The question was asked during a job interview.Question is from Random Module topic in section Mapping Functions and Modules of Python

Answer»

The CORRECT ANSWER is (d) [0.0, 1.0)

To explain: Any number that is GREATER than or equal to 0.0 and lesser than 1.0 can be RETURNED.

37.

Which type of elements are accepted by random.shuffle()?(a) strings(b) lists(c) tuples(d) integersI got this question by my school teacher while I was bunking the class.Query is from Random Module in division Mapping Functions and Modules of Python

Answer» RIGHT OPTION is (B) lists

For explanation: Strings and tuples are immutable and an integer has no LEN().
38.

What does random.shuffle(x) do when x = [1, 2, 3]?(a) error(b) do nothing, it is a placeholder for a function that is yet to be implemented(c) shuffle the elements of the list in-place(d) none of the mentionedThis question was posed to me during an interview for a job.The query is from Random Module topic in division Mapping Functions and Modules of Python

Answer»

Correct CHOICE is (c) shuffle the ELEMENTS of the list in-place

For EXPLANATION: The elements of the list PASSED to it are shuffled in-place.

39.

Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?(a) 0(b) 1(c) KeyError: 1(d) none of the mentionedI had been asked this question in my homework.This is a very interesting question from Random Module topic in division Mapping Functions and Modules of Python

Answer»

Correct answer is (a) 0

To EXPLAIN I would SAY: It will not print 0 but DICT[0] i.e. 1 MAY be printed.

40.

Which of the following will not be returned by random.choice(“1 ,”)?(a) 1(b) (space)(c) ,(d) none of the mentionedThis question was addressed to me in an internship interview.I want to ask this question from Random Module in chapter Mapping Functions and Modules of Python

Answer» RIGHT answer is (d) none of the mentioned

Best EXPLANATION: Any of the characters PRESENT in the string MAY be returned.
41.

Which of the following is equivalent to random.randint(3, 6)?(a) random.choice([3, 6])(b) random.randrange(3, 6)(c) 3 + random.randrange(3)(d) 3 + random.randrange(4)The question was asked at a job interview.I'm obligated to ask this question of Random Module in chapter Mapping Functions and Modules of Python

Answer»

The correct option is (d) 3 + random.randrange(4)

The EXPLANATION: random.randint(3, 6) can RETURN any ONE of 3, 4, 5 and 6.

42.

The function random.randint(4) can return only one of the following values. Which?(a) 4(b) 3.4(c) error(d) 5I had been asked this question in an interview for job.This is a very interesting question from Random Module in section Mapping Functions and Modules of Python

Answer»

The correct choice is (C) ERROR

To EXPLAIN I would SAY: Error, the function takes two arguments.

43.

Which of the following is equivalent to random.randrange(3)?(a) range(3)(b) random.choice(range(0, 3))(c) random.shuffle(range(3))(d) random.select(range(3))I had been asked this question in an online quiz.The question is from Random Module in chapter Mapping Functions and Modules of Python

Answer»

Right answer is (b) random.choice(range(0, 3))

EASIEST explanation - It returns one number from the GIVEN range.

44.

Which of the following cannot be returned by random.randrange(4)?(a) 0(b) 3(c) 2.3(d) none of the mentionedI got this question in a national level competition.My question is from Random Module in chapter Mapping Functions and Modules of Python

Answer»

The correct ANSWER is (c) 2.3

The BEST EXPLANATION: Only INTEGERS can be returned.

45.

What the does random.seed(3) return?(a) True(b) None(c) 3(d) 1This question was posed to me in class test.I'm obligated to ask this question of Random Module topic in chapter Mapping Functions and Modules of Python

Answer»

Correct choice is (B) None

Easiest EXPLANATION - The FUNCTION random.seed() always RETURNS a None.

46.

The randrange function returns only an integer value.(a) True(b) FalseThe question was asked in an online quiz.My question is taken from Random module topic in division Mapping Functions and Modules of Python

Answer»

The correct option is (a) True

Easy explanation - The function randrange RETURNS only an INTEGER value. Hence this STATEMENT is true.

47.

Both the functions randint and uniform accept ____________ parameters.(a) 0(b) 1(c) 3(d) 2This question was addressed to me in a job interview.The doubt is from Random module topic in portion Mapping Functions and Modules of Python

Answer»

Right CHOICE is (d) 2

Easiest explanation - Both of these functions, that is, randint and uniform are included in the RANDOM module and both of these functions accept 2 parameters. For example: random.uniform(a,b) where ‘a’ and ‘b’ SPECIFY the range.

48.

What is the interval of the value generated by the function random.random(), assuming that the random module has already been imported?(a) (0,1)(b) (0,1](c) [0,1](d) [0,1)I got this question by my school principal while I was bunking the class.Origin of the question is Random module in portion Mapping Functions and Modules of Python

Answer»

Correct choice is (d) [0,1)

To EXPLAIN: The function random.random() generates a random value in the INTERVAL [0,1), that is, INCLUDING ZERO but excluding one.

49.

To include the use of functions which are present in the random library, we must use the option:(a) import random(b) random.h(c) import.random(d) random.randomI had been asked this question in an interview for job.My question is taken from Random module topic in division Mapping Functions and Modules of Python

Answer» CORRECT option is (a) import RANDOM

The best I can explain: The COMMAND import random is used to import the random MODULE, which enables us to use the functions which are present in the random library.
50.

Which of the following functions helps us to randomize the items of a list?(a) seed(b) randomise(c) shuffle(d) uniformThis question was posed to me by my school principal while I was bunking the class.I want to ask this question from Random module in section Mapping Functions and Modules of Python

Answer»

The CORRECT choice is (C) shuffle

The BEST I can explain: The FUNCTION shuffle, which is included in the random module, helps us to RANDOMIZE the items of a list. This function takes the list as a parameter.