View
15
Download
0
Category
Preview:
Citation preview
Python Programming
Q. Class is used to add a container widget, which may consist of any number of panes arranged
vertically or horizontally.
a) LabelFrame
b) Spinbox
c) PanedWindow
d) Scrollbar
Answer: PanedWindow
Python Programming
Q. __________ is a way of solving a problem in which a function calls itself one or more times,
breaking down the problem into smaller sub-problems.
a) Break
b) Continue
c) Goto
d) Recursion
Answer: Recursion
Python Programming
Q. Consider the following line of code: list2 = list1[:], which operation is performed in this line of
code?
a) Reversing of list
b) Slicing of list
c) Appending of list
d) Cloning of list
Answer: Cloning of list
Python Programming
Q. Which of the following refers to a register used to store the address of the instruction currently
being executed by the thread?
a) Thread State
b) Stack Pointer
c) Program Counter
d) Thread Register Set
Answer: Program Counter
Python Programming
Q. A programmer wants to remove the items one-by-one in an efficient way from a dictionary.
Which of the following methods must be used by him/her?
a) pop()
b) remove()
c) removelastitem()
d) popitem()
Answer: popitem()
Python Programming
Q. A programmer wants to use an array data structure in a Python program. Which of the following
statements must be written at the top of the program?
a) import array *
b) import array
c) from array import *
d) from Python array import *
Answer: from array import *
Python Programming
Q. A programmer wants to create a list of heterogeneous datatypes that cannot be modified. Which
of the following data structures must be used by him/her?
a) List
b) Array
c) Dictionary
d) Tuple
Answer: Tuple
Python Programming
Q. Which of the following is not a law associated with recursion functions?
a) It must have a base case
b) It must be in uppercase
c) By changing its state, it must move towards the base case
d) It must call itself recursively
Answer: It must be in uppercase
Python Programming
Q. Which of the following data types has key-value pair?
a) Tuple
b) List
c) Dictionary
d) Boolean
Answer: Dictionary
Python Programming
Q. This is an ordered sequence of items, which is a collection of randomly typed objects with no
fixed size and type. Identify it.
a) String
b) List
c) Number
d) Float
Answer: List
Python Programming
Q. Python can be executed on different platforms without making any changes in the content.
Identify this feature of the Python programming language.
a) Portable
b) Simple
c) Object-Oriented
d) Interpreted
Answer: Portable
Python Programming
Q. Function returns string in printable form.
a) eval()
b) exec()
c) ascii()
d) bytearray()
Answer: ascii()
Python Programming
Q. John wants to perform the concatenation of the two strings. Which of the following operators
must be overloaded by him?
a) __mul__(self, other)
b) __sub__(self, other)
c) __mod__(self, other)
d) __add__(self, other)
Answer: __add__(self, other)
Python Programming
Q. John has created a large program consisting of many classes. While creating yet another class, he
realised that all the classes should have common methods. The thought of modifying all the classes
seemed to be very time-consuming. Which object oriented co
a) Operator overloading
b) An interface
c) An abstract class
d) Either B or C
Answer: Operator overloading
Python Programming
Q. A programmer wants to display the result as the addition of five numbers entered by him without
exiting the loop. Which of the following must be used by him or her?
a) break
b) continue
c) pass
d) while-else
Answer: pass
Python Programming
Q. A programmer wants to print two different strings in a line, but he/she wants to replace the
default separator with ‘&’. Which attribute of the print() function will be used?
a) end
b) sep
c) file
d) flush
Answer: end
Python Programming
Q. Which mode opens a file for both appending and reading in binary format
a) a+
b) rb+
c) ab+
d) wb+
Answer: ab+
Python Programming
Q. A programmer wants to obtain a value of an expression either in True or False. Which of the
following data types must be used by him/her?
a) Boolean
b) Number
c) Compound
d) String
Answer: Boolean
Python Programming
Q. which of the following is not a rule while naming an identifier in the Python programming?
a) Identifiers can be named by using a combination of letters
b) An identifier should start with a number
c) Keywords should not be used as the name of an identifier
d) Identifiers can be of any length
Answer: An identifier should start with a number
Python Programming
Q. Your friend has created a base class as A and a derived class as B. Identify the correct syntax to
call the method of the base class Ameth() in the derived class.
a) A.Ameth()
b) B.Ameth()
c) A().Ameth
d) B().Ameth
Answer: A.Ameth()
Python Programming
Q. Write the output of the following code: >>> New_String = ‘Python’ >>> print(New_String[2:4])
a) th
b) yth
c) Pyth
d) Python
Answer: th
Python Programming
Q. For calculating the area of a cube, which symbol must be used?
a) !
b) *
c) ^
d) $
Answer: ^
Python Programming
Q. A programmer wants to store the names of 50 students. Which of the following data structures
should be used by him/her?
a) Operators
b) Constants
c) Literals
d) Arrays
Answer: Arrays
Python Programming
Q. A programmer has assigned the values 2, 3 and 5 to a, b and c, respectively. To change the value
of a and c to 6 and b to 8, What will be the correct syntax?
a) a=c=+5, b=8
b) a=c=6, b=8
c) a=6, b=8
d) a=c+, b=8
Answer: a=c=6, b=8
Python Programming
Q. If a transaction consists of two or more tasks, these intermediate tasks must not be visible outside
the scope of the transaction. Which of the following characteristics ensures this?
a) Atomicity
b) Consistency
c) Isolation
d) Durability
Answer: Isolation
Python Programming
Q. __________ is a keyword, which indicates that the function header has started.
a) def
b) var
c) class
d) del
Answer: def
Python Programming
Q. This operator multiplies the given list for the specified number of times. Identify the operator.
a) “ * “
b) “ + ”
c) “ ^ “
d) “ ! “
Answer: “ * “
Python Programming
Q. Which of the following statements is used to terminate the loop?
a) continue
b) break
c) for
d) while
Answer: break
Python Programming
Q. The regular expressions in Python can only be used after importing the module, which provides
methods and functions to deal with regular expressions.
a) PyMySQL
b) RE
c) Expression
d) Pattern
Answer: RE
Python Programming
Q. If a programmer wants to check that a value or a variable is a member of a sequence, then which
operator should he/she prefer?
a) Membership
b) Logical
c) Assignment
d) Bitwise
Answer: Membership
Python Programming
Q. A programmer wants to convert a mutable list into an immutable tuple. Which function should
he/she use?
a) list(seq)
b) tuple(seq)
c) mutable(list)
d) convert(list)
Answer: tuple(seq)
Python Programming
Q. It is a connection-oriented and reliable communication protocol, wherein a connection is needed
to be established first between a pair of sockets. Identify the protocol.
a) Transmission Control Protocol
b) User Datagram Protocol
c) Hypertext Transfer Protocol
d) File Transfer Protocol
Answer: Transmission Control Protocol
Python Programming
Q. ???--Which of the following looping functions is used to iterate over a block of code only when
the test expression
a) for
b) If-else
c) if
d) while
Answer: while
Python Programming
Q. You want to transform your array into a new shape without altering the data. Which of the
following functions must be used?
a) rollaxis()
b) ndarray.T()
c) transpose()
d) reshape()
Answer: reshape()
Python Programming
Q. Who is referred to as the Father of the Python programming language?
a) Tim Berners Lee
b) Charles Babbage
c) Guido van Rossum
d) Ada Lovelace
Answer: Guido van Rossum
Python Programming
Q. In Python is an algorithm that resolves the call to an attribute or a method at runtime.
a) Algorithm order
b) Resolution
c) Method order
d) Method resolution order
Answer: Method resolution order
Python Programming
Q. This method sets the value of an attribute ‘attr’ to ‘val’ in object ‘obj’. It also creates an attribute
‘attr’ with value ‘val’ if no such attribute exits. Identify the method.
a) getattr(obj, attr)
b) setattr(obj, attr, val)
c) hasattr(obj, attr)
d) vars(obj)
Answer: setattr(obj, attr, val)
Python Programming
Q. __________ are unordered collections of objects indexed with the help of keys. They are basically
a set of key:value pairs and are implemented as hash tables.
a) List
b) Tuple
c) Array
d) Dictionaries
Answer: Dictionaries
Python Programming
Q. John has created three classes A, B and C. The classes A and B are the base classes. The class C is a
derived class that inherits methods of both base classes. Identify the type of inheritance.
a) Hierarchical
b) Multiple
c) Double
d) Single
Answer: Multiple
Python Programming
Q. A programmer wants to take input from the user, or programs need to read keyboard inputs
given by the user. Which function must be used?
a) print()
b) input()
c) read()
d) write()
Answer: input()
Python Programming
Q. It is a full-fledged Python package or library, containing objects of multi-dimensional arrays and
routines for processing these arrays. Identify it.
a) NumPy
b) Metrolib
c) Panda
d) SciPy
Answer: NumPy
Python Programming
Q. Constructor overriding in Python is also performed using __________ method.
a) Class
b) Super
c) Method
d) Function
Answer: Super
Python Programming
Q. Once the Python command is executed, the Python interpreter returns the Python statement to a
command prompt, which indicates that the interpreter is ready for the next command. Identify the
sign of the Python command prompt.
a) >>
b) >>>
c) <<
d) <<<
Answer: >>>
Python Programming
Q. In Python, the index of an element may be a negative number . If the index is -1, then which
element does it refer to in a list?
a) First element
b) Negative element
c) Last element
d) No element
Answer: Last element
Python Programming
Q. __________ returns a string of the name of the host where Python is currently being executing.
a) socket.getfqdn([name])
b) socket.gethostbyname(hostname)
c) socket.socket(family, type)
d) socket.gethostname()
Answer: socket.gethostname()
Python Programming
Q. A programmer wants to print a list in the reverse order. Which of the following commands should
he/she use?
a) (List[-1])
b) (List[::-1])
c) (List[::])
d) (List[reverse])
Answer: (List[::-1])
Python Programming
Q. Mary created two variables, x and y, with user-defined input and printed their addition. When she
executed the program, she gave two strings as ‘Computer’ and ‘Science’ as input. She thought there
will be an error, but she received the output as ‘Computer
a) Duck typing
b) Inheritance
c) Class
d) static binding
Answer: Duck typing
Python Programming
Q. A is a sequential collection of characters that are simply unit symbols.
a) String
b) Number
c) Float
d) Decimal
Answer: String
Python Programming
Q. You created a program where you want to use a constant value. You need to represent this
constant value with integer data type. What should be used?
a) Literal
b) Variable
c) Keyword
d) List
Answer: Literal
Python Programming
Q. Write the output of the following code: >>> Str = “High-level programming language is {0}” >>>
print(Str.format(‘Python’))
a) High-level programming language is Python
b) High-level programming language is {0}
c) “High-level programming language is Python”
d) High-level programming language is ‘Python’
Answer: High-level programming language is Python
Python Programming
Q. With the help of which keyword is it possible to create an empty dictionary?
a) dict()
b) NoValue()
c) Empty()
d) Null()
Answer: dict()
Python Programming
Q. A database connection in Python is created by using the method of the PyMySQL module.
a) database()
b) connect()
c) SQL()
d) SQLconnect()
Answer: connect()
Python Programming
Q. Consider the following line of code: def add(a, b). What are a and b referred to as in this line of
code?
a) Formal parameters
b) Actual parameters
c) Default Arguments
d) Constant Arguments
Answer: Formal parameters
Python Programming
Q. Which of the following languages is also known as Glue language?
a) C
b) C++
c) Python
d) Assembly
Answer: Python
Python Programming
Q. Which of the following is not a part of Python IDLE?
a) Code editor
b) Built-in automation tools
c) Debugger
d) Color Swatch
Answer: Color Swatch
Python Programming
Q. A programmer has typed a string as ‘I love my country’. Now he/she wants to replace the country
with ‘India’. Which of the following functions must be used by him/her?
a) replace()
b) search()
c) find()
d) sub()
Answer: replace()
Python Programming
Q. You want to calculate the sum of list [0, 2, 4, 6, 8, 10]. How many calls are made during the
execution of its code?
a) 3
b) 4
c) 5
d) 6
Answer: 5
Python Programming
Q. Which of the following is a correct syntax to declare dictionary?
a) Dictionary1 = (“key_name” : “value”)
b) Dictionary1 = {“key_name” : “value”}
c) Dictionary1 = [“key_name” : “value”]
d) Dictionary1 = “key_name” : “value”
Answer: Dictionary1 = {“key_name” : “value”}
Python Programming
Q. A program consists of an abstract class TVSeries, deriving classes GameOfThrones and Friends.
The TVSeries includes a method display(). With the help of which keyword can the derived class
access the abstract class method?
a) def
b) access
c) super
d) base
Answer: super
Python Programming
Q. A programmer wants to create a function without any name which can take any number of
arguments. Which of the following keywords is used for the same?
a) Def
b) Lambda
c) Anonymous
d) Var
Answer: Lambda
Python Programming
Q. Consider the following code snippet: >>> my_list = (‘Kim’, 2656, 31, ‘John’) >>> print(my-list(4))
While executing it, Python IDLE throws an error as TypeError: ‘tuple’ object is not callable. What is
the cause of this error?
a) List is not declared properly
b) The syntax for the print(my_list(4)) is incorrect
c) Use printf() function instead of print() function
d) List must include minimum five elements
Answer: The syntax for the print(my_list(4)) is incorrect
Python Programming
Q. There are four classes in a program, viz., A, B, C and D. Class B inherits class A and class D inherits
class C. Which type of inheritance is depicted here?
a) Single
b) Multiple
c) Double
d) Hierarchical
Answer: Single
Python Programming
Q. Write the output of the following: >>> New_tuple = (450, ‘Program’, 11.2, 13) >>>
print(New_tuple[2:])
a) (450, ‘Program’, 11.2, 13)
b) (‘Program’, 11.2, 13)
c) (450, ‘Program’)
d) (11.2, 13)
Answer: (11.2, 13)
Python Programming
Q. Joe writes a program that opens a file in read/write mode. She does not want the file to be left
open in case her program throws an exception. In which block should she write the code to close the
file?
a) try
b) else
c) finally
d) close
Answer: finally
Python Programming
Q. Write the output of the following code: >>> New_String = ‘Python’ >>> print(New_String[-4])
a) Pyth
b) thon
c) h
d) t
Answer: t
Python Programming
Q. Write the output of the following code: >>> from array import * >>> new_array = array(‘i’, [63,
559, 665, 1206]) >>> new_array.reverse() >>> print(new_array)
a) [1206, 665, 559, 63]
b) array([1206, 665, 559, 63])
c) array(‘i’, [1206, 665, 559, 63])
d) new_array(‘i’, [1206, 665, 559, 63])
Answer: array(‘i’, [1206, 665, 559, 63])
Python Programming
Q. This version of the Python, released in 2000, had new features to support memory management
and Unicode. Memory management was done with the help of a cycle-detecting garbage collector in
this version. Identify the version of the Python.
a) Python 3.0
b) Python 2.0
c) Python 3.6.1
d) Python 2.6
Answer: Python 2.0
Python Programming
Q. What does 'i' represent in the following line of code? >>> new_array = array('i', [63, 559, 665,
1206])
a) It represents a Unicode character of size 2 bytes
b) It represents a signed integer of size 2 bytes
c) It represents an unsigned integer of size 2 bytes
d) It represents a Unicode character of size 4 bytes
Answer: It represents a signed integer of size 2 bytes
Python Programming
Q. If you wish to delete any directory, you must ensure to remove all the contents of the directory
before deleting it. Which of the following function must be used for this?
a) rmdir()
b) delete()
c) terminate()
d) close()
Answer: rmdir()
Python Programming
Q. Mary created a GUI that consists of several widgets. She wants to arrange these widgets at
absolute positions in the root window. Which layout manager will be suitable for this purpose?
a) Place
b) Grid
c) Pack
d) Absolute
Answer: Place
Python Programming
Q. Which of the following is not a GUI-based programming module of Python?
a) Tkinter
b) PyQt
c) JPython
d) NumPy
Answer: NumPy
Python Programming
Q. A programmer uses a float value in an index number. It will lead to an error. Which of the
following errors is thrown by a compiler?
a) IndexError
b) FloatError
c) TypeError
d) TypoError
Answer: IndexError
Python Programming
Q. Which of the following looping structures is used to perform operations on arrays in the Python
programming language?
a) if
b) if-else
c) while-else
d) for
Answer: for
Python Programming
Q. The flow statement break the flow of a program by including decision making, looping and
branching statements.
a) Control
b) Correct
c) TRUE
d) Logical
Answer: Control
Python Programming
Q. Which of the following represents the newline character?
a) /w
b) /t
c) /l
d) /n
Answer: /n
Python Programming
Q. Consider the following list created in Python: my_list = [11, 12, 13, 14, 15, 16, 17, 18]. The
programmer wants to print only [13, 14, 15]. Which of the following commands must be used?
a) List[3:5]
b) List[2:5]
c) List[2:6]
d) List[3:6]
Answer: List[2:5]
Python Programming
Q. It is a Python flavour with which you can generate a standalone binary executables from the
Python programs. Identify it.
a) Class
b) Information
c) Data
d) Frozen binary
Answer: Frozen binary
Python Programming
Q. A programmer wants to save the Python file. Which of the following extensions should he/she
use?
a) .python
b) .pyt
c) .py
d) .class
Answer: .py
Python Programming
Q. Which of the following are used as place holders to fit in the variables or strings while formatting
an output?
a) Square brackets
b) Curly braces
c) Round brackets
d) Inverted commas
Answer: Curly braces
Python Programming
Q. An application, developed in the Python programming language, is used in an organisation to
manage the data of employees' details, such as salaries of employees, number of employees, login
hours of employees, etc. Which of the following data types must be
a) Character
b) String
c) Numeric
d) Boolean
Answer: Numeric
Python Programming
Q. You have created a module which contains two attributes -- calculating cube root and calculating
square root. Now, you want to import only square root. How will you do it?
a) import' statement
b) import… from
c) from…import…
d) from…import*
Answer: from…import…
Python Programming
Q. It has the Python shell window (interactive interpreter) with colouring feature of error message,
input and output on the screen. It also supports multi-window text editor. Identify It.
a) Interpreter
b) Debugger
c) Python IDLE
d) Compiler
Answer: Python IDLE
Python Programming
Q. Which of the following is a user-defined data types that contains certain attributes to define an
object?
a) Data member
b) Class
c) Method
d) Function
Answer: Class
Python Programming
Q. A programmer wants to exit the function and go back to the place where it was called from.
Which of the following functions should he/she use?
a) start()
b) return()
c) jump()
d) goto()
Answer: return()
Python Programming
Q. A programmer wants to find all the instances of a pattern in a string without overlapping. Name
the function used.
a) findall()
b) search()
c) find()
d) all()
Answer: findall()
Python Programming
Q. An is a collection of homogenous values that can be used to implement other data structures,
such as stacks, linked lists and queues.
a) Operator
b) Keyword
c) Array
d) Dictionary
Answer: Array
Python Programming
Q. __________ are the special symbols, which carry out the arithmetic or logical computations on
the operands and generate an output.
a) Keyword
b) Variable
c) Operators
d) Literals
Answer: Operators
Python Programming
Q. A literal is a notation for representing a value of a built-in data type.
a) variable
b) array
c) boolean
d) constant
Answer: constant
Python Programming
Q. Your friend wants to create a record for the car names, such as Honda, Maruti and Ford. Which of
the following names depicts the name of the class corrrectly?
a) Ford
b) Honda
c) Car
d) Maruti
Answer: Car
Python Programming
Q. A programmer wants to use PyMySQL module in a program, but when he/she is executing the
program, a fatal error (ModuleNotFoundError) is thrown by the compiler. Which command is used
to import this module?
a) install PyMySQL
b) pip PyMySQL
c) get PyMySQL
d) pip install PyMySQL
Answer: pip install PyMySQL
Python Programming
Q. Which of the following operators is used to concatenate strings?
a) "#"
b) "&"
c) "+"
d) "*"
Answer: "+"
Python Programming
Q. Your friend wants to declare a constructor. Which of the following syntax should he/she use?
a) def (self, <parameter list>): #body of the constructor
b) init__ (self, <parameter list>): #body of the constructor
c) def __init__ (self, <parameter list>): #body of the constructor
d) def __init__ (self, <parameter list>) #body of the constructor
Answer: def __init__ (self, <parameter list>): #body of the constructor
Python Programming
Q. A programmer wants to close an opened file. Identify the correct syntax for closing the file in
Python.
a) fileobject.close()
b) close()
c) fileclose()
d) close.fileobject()
Answer: fileobject.close()
Python Programming
Q. Calculate the value of the following code snippet: >>> a=10 >>> b=7 >>> c=3 >>> print(a*b//c)
a) 23
b) 23.3
c) 20
d) 24
Answer: 23
Python Programming
Q. A programmer wants to delete a list in a program. Which of the following keywords is used for
the same?
a) delete
b) close
c) terminate
d) del
Answer: del
Python Programming
Q. A programmer needs to check multiple statements for 'True' condition. If any of the statements is
'True', it executes the associated block of code. Which of the following control statements must be
used by him/her?
a) if
b) If-else
c) if-else-if
d) if-elif-else
Answer: if-elif-else
Python Programming
Q. In this approach, the functions and the data of a program are wrapped in a unit. Name the
approach.
a) Procedure-Oriented
b) Function-Oriented
c) Object-Oriented
d) Class-Oriented
Answer: Object-Oriented
Python Programming
Q. A programmer has added a list of fruit names as list ['Apple', 'banana', 'Gauva']. He/She wants to
print the list that contains the length of each name. Write the function used for this.
a) Lambda function
b) Lambda + filter() + len()
c) Lambda + len()
d) Lambda + map() + len()
Answer: Lambda + map() + len()
Python Programming
Q. Consider the following code snippet: >>> add = 0 >>> def addition (a, b): >>> add = a + b >>>
print(""The result is:"", add) >>> addition (200, 300) >>> print(""The result is :"", add) Predict its
output.
a) 500 0
b) 500 500
c) 0 0
d) 0 500
Answer: 500 0
Python Programming
Q. Your friend has created a base class Car but has not defined any methods such as getColor() and
getName() in it. The methods are defined in the derived classes, such as Ford and Honda. Which of
the following is inherited by the derived classes?
a) Abstract base class
b) Static base class
c) Main base class
d) Derived base class
Answer: Main base class
Python Programming
Q. Which of the following is not a rich Python IDLE?
a) PyCharm
b) IntelliJ IDEA
c) PyDev
d) Emacs
Answer: IntelliJ IDEA
Python Programming
Q. A programmer types a line as: >>> printf("Python Programming Language") When this line of code
is executed, an error is encountered. Find the correct syntax to display the output.
a) Print("Python Programming Language")
b) print(Python Programming Language)
c) printing("Python Programming Language")
d) print("Python Programming Language")
Answer: print("Python Programming Language")
Python Programming
Q. Which of the following is not an advantage of Python programming language?
a) Python has a clearly defined syntax
b) In the interactive mode, Python has proven to be quite useful
c) Python has its own Integrated Development Environment called IDLE
d) Python requires more testing time when application are executed
Answer: Python requires more testing time when application are executed
Python Programming
Q. A programmer wants to make sure that no buffering is performed when the file opens. What
value must be set for the buffer attribute in the open() function?
a) complex
b) negative
c) positive
d) zero
Answer: zero
Python Programming
Q. In the Python programming language, first the source code is compiled to the bytecode; then it is
forwarded to the for execution that runs the scripts by iterating through the bytecode instructions,
one by one, to perform operations.
a) Java Virtual Machine
b) Python Virtual Machine
c) Assembler
d) Interpreter
Answer: Interpreter
Python Programming
Q. Which of the following is not an advantage of using function in the Python programming
language?
a) Functions ensure code reusability
b) Functions ensure code readability
c) Functions restrict the easy modification of the code
d) Functions make a program manageable
Answer: Functions restrict the easy modification of the code
Python Programming
Q. A text file comprises a sequence of lines which is terminated by a special character. Identify this
special character.
a) Terminate
b) End sequence
c) Line end
d) End of Line (EOL)
Answer: End of Line (EOL)
Recommended