0% found this document useful (0 votes)
2 views

Computer Science questions and answers

The document contains a compilation of questions and answers related to Python programming, covering topics such as language development, programming types, syntax rules, and built-in functions. Each question includes multiple-choice answers along with explanations for the correct answers. The document serves as a study guide for individuals looking to enhance their understanding of Python.

Uploaded by

688psv5j76
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Computer Science questions and answers

The document contains a compilation of questions and answers related to Python programming, covering topics such as language development, programming types, syntax rules, and built-in functions. Each question includes multiple-choice answers along with explanations for the correct answers. The document serves as a study guide for individuals looking to enhance their understanding of Python.

Uploaded by

688psv5j76
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

CSC 201 QUESTIONS AND ANSWERS COMPLIED BY PECULIAR GRACE AND SIR

KENNY

For more info


08102585379

1. Who developed Python Programming Language?


a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
View Answer

Answer: c
Explanation: Python language is designed by a Dutch programmer Guido van Rossum in the
Netherlands.

2. Which type of Programming does Python support?


a) object-oriented programming
b) structured programming
c) functional programming
d) all of the mentioned
View Answer
Answer: d
Explanation: Python is an interpreted programming language, which supports object-oriented,
structured, and functional programming.
3. Is Python case sensitive when dealing with identifiers?
a) no
b) yes
c) machine dependent
d) none of the mentioned
View Answer

Answer: b
Explanation: Case is always significant while dealing with identifiers in python.
4. Which of the following is the correct extension of the Python file?
a) .python
b) .pl
c) .py
d) .p
View Answer

Answer: c
Explanation: ‘.py’ is the correct extension of the Python file. Python programs can be written in
any text editor. To save these programs we need to save in files with file extension ‘.py’.
5. Is Python code compiled or interpreted?
a) Python code is both compiled and interpreted
b) Python code is neither compiled nor interpreted
c) Python code is only compiled
d) Python code is only interpreted
View Answer

Answer: a
Explanation: Many languages have been implemented using both compilers and interpreters,
including C, Pascal, and Python.
advertisement

6. All keywords in Python are in _________


a) Capitalized
b) lower case
c) UPPER CASE
d) None of the mentioned
View Answer

Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.
7. What will be the value of the following Python expression?
4+ 3%5
a) 7
b) 2
c) 4
d) 1
View Answer

Answer: a
Explanation: The order of precedence is: %, +. Hence the expression above, on simplification
results in 4 + 3 = 7. Hence the result is 7.

8. Which of the following is used to define a block of code in Python language?


a) Indentation
b) Key
c) Brackets
d) All of the mentioned
View Answer

Answer: a
Explanation: In Python, to define a block of code we use indentation. Indentation refers to
whitespaces at the beginning of the line.
9. Which keyword is used for function in Python language?
a) Function
b) def
c) Fun
d) Define
View Answer

Answer: b
Explanation: The def keyword is used to create, (or define) a function in python.
10. Which of the following character is used to give single-line comments in Python?
a) //
b) #
c) !
d) /*
View Answer

Answer: b
Explanation: To write single-line comments in Python use the Hash character (#) at the beginning
of the line. It is also called number sign or pound sign. To write multi-line comments, close the text
between triple quotes.
Example: “”” comment
text “””
11. What will be the output of the following Python code?

i=1
while True:
if i%3 == 0:
break
print(i)

i+=1
a) 1 2 3
b) error
c) 1 2
d) none of the mentioned
View Answer

Answer: b
Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.

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

Answer: d
Explanation: The function sys.version can help us to find the version of python that we are
currently working on. It also contains information on the build number and compiler used. For
example, 3.5.2, 2.7.3 etc. this function also returns the current date, time, bits etc along with the
version.

13. Python supports the creation of anonymous functions at runtime, using a construct called
__________
a) pi
b) anonymous
c) lambda
d) none of the mentioned
View Answer

Answer: c
Explanation: Python supports the creation of anonymous functions (i.e. functions that are not
bound to a name) at runtime, using a construct called lambda. Lambda functions are restricted to a
single expression. They can be used wherever normal functions can be used.
14. What is the order of precedence in python?
a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
View Answer

Answer: d
Explanation: For order of precedence, just remember this PEMDAS (similar to BODMAS).
15. What will be the output of the following Python code snippet if x=1?

x<<2
a) 4
b) 2
c) 1
d) 8
View Answer

Answer: a
Explanation: The binary form of 1 is 0001. The expression x<<2 implies we are performing bitwise
left shift on x. This shift yields the value: 0100, which is the binary form of the number 4.
16. What does pip stand for python?
a) Pip Installs Python
b) Pip Installs Packages
c) Preferred Installer Program
d) All of the mentioned
View Answer

Answer: c
Explanation: pip is a package manager for python. Which is also called Preferred Installer Program.

17. Which of the following is true for variable names in Python?


a) underscore and ampersand are the only two special characters allowed
b) unlimited length
c) all private members must have leading and trailing underscores
d) none of the mentioned
View Answer

Answer: b
Explanation: Variable names can be of any length.
18. What are the values of the following Python expressions?

2**(3**2)
(2**3)**2
2**3**2
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
View Answer

Answer: a
Explanation: Expression 1 is evaluated as: 2**9, which is equal to 512. Expression 2 is evaluated as
8**2, which is equal to 64. The last expression is evaluated as 2**(3**2). This is because the
associativity of ** operator is from right to left. Hence the result of the third expression is 512.
19. Which of the following is the truncation division operator in Python?
a) |
b) //
c) /
d) %
View Answer

Answer: b
Explanation: // is the operator for truncation division. It is called so because it returns only the
integer part of the quotient, truncating the decimal part. For example: 20//3 = 6.

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

l=[1, 0, 2, 0, 'hello', '', []]


list(filter(bool, l))
a) [1, 0, 2, ‘hello’, ”, []]
b) Error
c) [1, 2, ‘hello’]
d) [1, 0, 2, 0, ‘hello’, ”, []]
View Answer

Answer: c
Explanation: The code shown above returns a new list containing only those elements of the list l
which do not amount to zero. Hence the output is: [1, 2, ‘hello’].

21. Which of the following functions is a built-in function in python?


a) factorial()
b) print()
c) seed()
d) sqrt()
View Answer

Answer: b
Explanation: The function seed is a function which is present in the random module. The functions
sqrt and factorial are a part of the math module. The print function is a built-in function which
prints a value directly to the system output.

22. Which of the following is the use of id() function in python?


a) Every object doesn’t have a unique id
b) Id returns the identity of the object
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: b
Explanation: Each object in Python has a unique id. The id() function returns the object’s id.
23. The following python program can work with ____ parameters.

def f(x):
def f1(*args, **kwargs):
print("Sanfoundry")
return x(*args, **kwargs)
return f1
a) any number of
b) 0
c) 1
d) 2
View Answer

Answer: a
Explanation: The code shown above shows a general decorator which can work with any number of
arguments.

24. What will be the output of the following Python function?


min(max(False,-3,-4), 2,7)
a) -4
b) -3
c) 2
d) False
View Answer

Answer: d
Explanation: The function max() is being used to find the maximum value from among -3, -4 and
false. Since false amounts to the value zero, hence we are left with min(0, 2, 7) Hence the output is 0
(false).

25. Which of the following is not a core data type in Python programming?
a) Tuples
b) Lists
c) Class
d) Dictionary
View Answer

Answer: c
Explanation: Class is a user-defined data type.
26. What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)
a) 56.236
b) 56.23
c) 56.0000
d) 56.24
View Answer

Answer: d
Explanation: The expression shown above rounds off the given number to the number of decimal
places specified. Since the expression given specifies rounding off to two decimal places, the
output of this expression will be 56.24. Had the value been x=56.234 (last digit being any number
less than 5), the output would have been 56.23.

27. Which of these is the definition for packages in Python?


a) A set of main modules
b) A folder of python modules
c) A number of files containing Python definitions and statements
d) A set of programs making use of Python modules
View Answer

Answer: b
Explanation: A folder of python programs is called as a package of modules.
28. What will be the output of the following Python function?
len(["hello",2, 4, 6])
a) Error
b) 6
c) 4
d) 3
View Answer

Answer: c
Explanation: The function len() returns the length of the number of elements in the iterable.
Therefore the output of the function shown above is 4.

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


x = 'abcd'
for i in x:
print(i.upper())
a)

a
B
C
D
b) a b c d
c) error
d)

A
B
C
D
View Answer
Answer: d
Explanation: The instance of the string returned by upper() is being printed.

30. What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the built-in namespace, then the global namespace and finally the local
namespace
b) Python first searches the built-in namespace, then the local namespace and finally the global
namespace
c) Python first searches the local namespace, then the global namespace and finally the built-in
namespace
d) Python first searches the global namespace, then the local namespace and finally the built-in
namespace
View Answer

Answer: c
Explanation: Python first searches for the local, then the global and finally the built-in namespace.

31. What will be the output of the following Python code snippet?

for i in [1, 2, 3, 4][::-1]:


print (i)
a) 4 3 2 1
b) error
c) 1 2 3 4
d) none of the mentioned
View Answer

Answer: a
Explanation: [::-1] reverses the list.

32. What will be the output of the following Python statement?

>>>"a"+"bc"
a) bc
b) abc
c) a
d) bca
View Answer

Answer: b
Explanation: + operator is concatenation operator.

33. Which function is called when the following Python program is executed?

f = foo()
format(f)
a) str()
b) format()
c) __str__()
d) __format__()
View Answer

Answer: c
Explanation: Both str(f) and format(f) call f.__str__().

34. Which one of the following is not a keyword in Python language?


a) pass
b) eval
c) assert
d) nonlocal
View Answer

Answer: b
Explanation: eval can be used as a variable.

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

class tester:
def __init__(self, id):
self.id = str(id)
id="224"

>>>temp = tester(12)
>>>print(temp.id)
a) 12
b) 224
c) None
d) Error
View Answer

Answer: a
Explanation: Id in this case will be the attribute of the instance.

36. What will be the output of the following Python program?

def foo(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
a) Error
b) None
c) False
d) True
View Answer

Answer: d
Explanation: The same object is modified in the function.

37. Which module in the python standard library parses options received from the command line?
a) getarg
b) getopt
c) main
d) os
View Answer

Answer: b
Explanation: getopt parses options received from the command line.

38. What will be the output of the following Python program?

z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
z
a) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
b) {‘abc’, ‘p’, ‘q’, ‘san’}
c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
d) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
View Answer

Answer: c
Explanation: The code shown first adds the element ‘san’ to the set z. The set z is then updated
and two more elements, namely, ‘p’ and ‘q’ are added to it. Hence the output is: {‘a’, ‘b’, ‘c’,
‘p’, ‘q’, ‘san’}

39. What arithmetic operators cannot be used with strings in Python?


a) *
b) –
c) +
d) All of the mentioned
View Answer

Answer: b
Explanation: + is used to concatenate and * is used to multiply strings.

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

print("abc. DEF".capitalize())
a) Abc. def
b) abc. def
c) Abc. Def
d) ABC. DEF
View Answer

Answer: a
Explanation: The first letter of the string is converted to uppercase and the others are converted to
lowercase.

41. Which of the following statements is used to create an empty set in Python?
a) ( )
b) [ ]
c) { }
d) set()
View Answer
Answer: d
Explanation: { } creates a dictionary not a set. Only set() creates an empty set.

42. What will be the value of ‘result’ in following Python program?

list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
result.extend(i for i in list1 if i not in (list2+list3) and i not in result)
result.extend(i for i in list2 if i not in (list1+list3) and i not in result)
result.extend(i for i in list3 if i not in (list1+list2) and i not in result)
a) [1, 3, 5, 7, 8]
b) [1, 7, 8]
c) [1, 2, 4, 7, 8]
d) error
View Answer

Answer: a
Explanation: Here, ‘ result ’ is a list which is extending three times. When first time ‘ extend ’
function is called for ‘result’, the inner code generates a generator object, which is further used in
‘extend’ function. This generator object contains the values which are in ‘list1’ only (not in ‘list2’
and ‘list3’).
Same is happening in second and third call of ‘extend’ function in these generator object contains
values only in ‘list2’ and ‘list3’ respectively.
So, ‘result’ variable will contain elements which are only in one list (not more than 1 list).

43. To add a new element to a list we use which Python command?


a) list1.addEnd(5)
b) list1.addLast(5)
c) list1.append(5)
d) list1.add(5)
View Answer

Answer: c
Explanation: We use the function append to add an element to the list.

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

print('*', "abcde".center(6), '*', sep='')


a) * abcde *
b) *abcde *
c) * abcde*
d) * abcde *
View Answer

Answer: b
Explanation: Padding is done towards the right-hand-side first when the final string is of even
length.

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

>>>list1 = [1, 3]
>>>list2 = list1
>>>list1[0] = 4
>>>print(list2)
a) [1, 4]
b) [1, 3, 4]
c) [4, 3]
d) [1, 3]
View Answer

Answer: c
Explanation: Lists should be copied by executing [:] operation.

46. Which one of the following is the use of function in python?


a) Functions don’t provide better modularity for your application
b) you can’t also create your own functions
c) Functions are reusable pieces of programs
d) All of the mentioned
View Answer

Answer: c
Explanation: Functions are reusable pieces of programs. They allow you to give a name to a block
of statements, allowing you to run that block using the specified name anywhere in your program
and any number of times

47. Which of the following Python statements will result in the output: 6?

A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
a) A[2][1]
b) A[1][2]
c) A[3][2]
d) A[2][3]
View Answer
Answer: b
Explanation: The output that is required is 6, that is, row 2, item 3. This position is represented by
the statement: A[1][2].

48. What is the maximum possible length of an identifier in Python?


a) 79 characters
b) 31 characters
c) 63 characters
d) none of the mentioned
View Answer

Answer: d
Explanation: Identifiers can be of any length.

49. What will be the output of the following Python program?

i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) error
b) 0 1 2 0
c) 0 1 2
d) none of the mentioned
View Answer

Answer:
Explanation: The else part is not executed if control breaks out of the loop.

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

x = 'abcd'
for i in range(len(x)):
print(i)
a) error
b) 1 2 3 4
c) a b c d
d) 0 1 2 3
View Answer
Answer: d
Explanation: i takes values 0, 1, 2 and 3.

51. What are the two main types of functions in Python?


a) System function
b) Custom function
c) Built-in function & User defined function
d) User function
View Answer

Answer: c
Explanation: Built-in functions and user defined ones. The built-in functions are part of the Python
language. Examples are: dir(), len() or abs(). The user defined functions are functions created with
the def keyword.

52. What will be the output of the following Python program?

def addItem(listParam):
listParam += [1]

mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))
a) 5
b) 8
c) 2
d) 1
View Answer

Answer: a
Explanation: + will append the element to the list.

53. Which of the following is a Python tuple?


a) {1, 2, 3}
b) {}
c) [1, 2, 3]
d) (1, 2, 3)
View Answer

Answer: d
Explanation: Tuples are represented with round brackets.
54. What will be the output of the following Python code snippet?

z=set('abc$de')
'a' in z
a) Error
b) True
c) False
d) No output
View Answer

Answer: b
Explanation: The code shown above is used to check whether a particular item is a part of a given
set or not. Since ‘a’ is a part of the set z, the output is true. Note that this code would result in an
error in the absence of the quotes.

55. What will be the output of the following Python expression?

round(4.576)
a) 4
b) 4.6
c) 5
d) 4.5
View Answer

Answer: c
Explanation: This is a built-in function which rounds a number to give precision in decimal digits.
In the above case, since the number of decimal places has not been specified, the decimal number
is rounded off to a whole number. Hence the output will be 5.

56. Which of the following is a feature of Python DocString?


a) In Python all functions should have a docstring
b) Docstrings can be accessed by the __doc__ attribute on objects
c) It provides a convenient way of associating documentation with Python modules, functions,
classes, and methods
d) All of the mentioned
View Answer

Answer: d
Explanation: Python has a nifty feature called documentation strings, usually referred to by its
shorter name docstrings. DocStrings are an important tool that you should make use of since it
helps to document the program better and makes it easier to understand.

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

print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))


a) Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
b) Error
c) Hello foo and bin
d) None of the mentioned
View Answer

Answer: c
Explanation: The elements of the tuple are accessed by their indices.

58. What is output of print(math.pow(3, 2))?


a) 9.0
b) None
c) 9
d) None of the mentioned
View Answer

Answer: a
Explanation: math.pow() returns a floating point number.

59. Which of the following is the use of id() function in python?


a) Every object in Python doesn’t have a unique id
b) In Python Id function returns the identity of the object
c) None of the mentioned
d) All of the mentioned
View Answer

Answer: b
Explanation: Each object in Python has a unique id. The id() function returns the object’s id.

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


x = [[0], [1]]
print((' '.join(list(map(str, x))),))
a) 01
b) [0] [1]
c) (’01’)
d) (‘[0] [1]’,)
View Answer

Answer: d
Explanation: (element,) is not the same as element. It is a tuple with one item.
61. The process of pickling in Python includes ____________
a) conversion of a Python object hierarchy into byte stream
b) conversion of a datatable into a list
c) conversion of a byte stream into Python object hierarchy
d) conversion of a list into a datatable
View Answer
Answer: a
Explanation: Pickling is the process of serializing a Python object, that is, conversion of a Python
object hierarchy into a byte stream.

61. Which is the correct operator for power(xy)?


a) X^y
b) X**y
c) X^^y
d) None of the mentioned
View Answer

Answer: b
Explanation: In python, power operator is x**y i.e. 2**3=8.

62. Which one of these is floor division?


a) /
b) //
c) %
d) None of the mentioned
View Answer

Answer: b
Explanation: When both of the operands are integer then python chops out the fraction part and
gives you the round off value, to get the accurate answer use floor division. This is floor division.
For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. To
get the 2.5 answer, use floor division.

63. What is the order of precedence in python?


i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction
a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,iv,vi,v
View Answer

Answer: a
Explanation: For order of precedence, just remember this PEMDAS (similar to BODMAS).
Subscribe Now: Python Newsletter | Important Subjects Newsletters.
64. What is the answer to this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5
View Answer

Answer: b
Explanation: Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1.

65. Mathematical operations can be performed on a string.


a) True
b) False
View Answer

Answer: b
Explanation: You can’t perform mathematical operation on string even if the string is in the form:
‘1234…’.
Become Top Ranker in Python Programming Now!

66. Operators with the same precedence are evaluated in which manner?
a) Left to Right
b) Right to Left
c) Can’t say
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

67. What is the output of this expression, 3*1**3?


a) 27
b) 9
c) 3
d) 1
View Answer

Answer: c
Explanation: First this expression will solve 1**3 because exponential has higher precedence than
multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.

68. Which one of the following has the same precedence level?
a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication
View Answer

Answer: a
Explanation: “ Addition and Subtraction ” are at the same precedence level. Similarly,
“ Multiplication and Division ” are at the same precedence level. However, Multiplication and
Division operators are at a higher precedence level than Addition and Subtraction operators.

69. The expression Int(x) implies that the variable x is converted to integer.
a) True
b) False
View Answer

Answer: a
Explanation: Int(x) converts the datatype of the variable to integer and is the example of explicit
data conversion.

70. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
View Answer

Answer: d
Explanation: Just remember: PEMDAS, that is, Parenthesis, Exponentiation, Division,
Multiplication, Addition, Subtraction. Note that the precedence order of Division and
Multiplication is the same. Likewise, the order of Addition and Subtraction is also the same.

71. Is Python case sensitive when dealing with identifiers?


a) yes
b) no
c) machine dependent
d) none of the mentioned
View Answer

Answer: a
Explanation: Case is always significant while dealing with identifiers in python.

72. What is the maximum possible length of an identifier?


a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned
View Answer

Answer: d
Explanation: Identifiers can be of any length.

73. Which of the following is invalid?


a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned
View Answer

Answer: d
Explanation: All the statements will execute successfully but at the cost of reduced readability.

74. Which of the following is an invalid variable?


a) my_string_1
b) 1st_string
c) foo
d) _
View Answer

Answer: b
Explanation: Variable names should not start with a number.

75. Why are local variable names beginning with an underscore discouraged?
a) they are used to indicate a private variables of a class
b) they confuse the interpreter
c) they are used to indicate global variables
d) they slow down execution
View Answer

Answer: a
Explanation: As Python has no concept of private variables, leading underscores are used to
indicate variables that must not be accessed from outside the class.

76. Which of the following is not a keyword?


a) eval
b) assert
c) nonlocal
d) pass
View Answer

Answer: a
Explanation: eval can be used as a variable.

77. All keywords in Python are in _________


a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned
View Answer

Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.

78. Which of the following is true for variable names in Python?


a) unlimited length
b) all private members must have leading and trailing underscores
c) underscore and ampersand are the only two special characters allowed
d) none of the mentioned
View Answer

Answer: a
Explanation: Variable names can be of any length.

79. Which of the following is an invalid statement?


a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
View Answer

Answer: b
Explanation: Spaces are not allowed in variable names.

80. Which of the following cannot be a variable?


a) __init__
b) in
c) it
d) on
View Answer
Answer: b
Explanation: in is a keyword
Types”.

81. Which of these in not a core data type?


a) Lists
b) Dictionary
c) Tuples
d) Class
View Answer

Answer: d
Explanation: Class is a user defined data type.

82. Given a function that does not return any value, What value is thrown by default when executed
in shell.
a) int
b) bool
c) void
d) None
View Answer

Answer: d
Explanation: Python shell throws a NoneType object back.

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


>>>str="hello"
>>>str[:2]
>>>
a) he
b) lo
c) olleh
d) hello
View Answer

Answer: a
Explanation: We are printing only the 1st two bytes of string and hence the answer is “he”.

84. Which of the following will run without errors?


a) round(45.8)
b) round(6352.898,2,5)
c) round()
d) round(7463.123,2,1)
View Answer
Answer: a
Explanation: Execute help(round) in the shell to get details of the parameters that are passed into
the round function.

85. What is the return type of function id?


a) int
b) float
c) bool
d) dict
View Answer

Answer: a
Explanation: Execute help(id) to find out details in python shell.id returns a integer value that is
unique.

86. In python we do not specify types, it is directly interpreted by the compiler, so consider the
following operation to be performed.

>>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
d) All of the mentioned
View Answer

Answer: d
Explanation: // is integer operation in python 3.0 and int(..) is a type cast operator.
advertisement

87. What error occurs when you execute the following Python code snippet?

apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
View Answer

Answer: b
Explanation: Mango is not defined hence name error.

88. What will be the output of the following Python code snippet?
def example(a):
a = a + '2'
a = a*2
return a
>>>example("hello")
a) indentation Error
b) cannot perform mathematical operation on strings
c) hello2
d) hello2hello2
View Answer

Answer: a
Explanation: Python codes have to be indented properly.

89. What data type is the object below?

L = [1, 23, 'hello', 1]


a) list
b) dictionary
c) array
d) tuple
View Answer

Answer: a
Explanation: List data type can store any values within it.

90. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary

Answer: d
Explanation: Dictionary stores values in terms of keys and values.

91. Which of the following results in a SyntaxError?


a) ‘”Once upon a time…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”’
View Answer
Answer: c
Explanation: Carefully look at the colons.
92. The following is displayed by a print function call. Select all of the function calls that result in
this output.

tom
dick
harry
a)print('''tom\ndick\nharry''')
b) print(”’tomdickharry”’)
c) print(‘tom\ndick\nharry’)
d)print('tomdickharry')
View Answer
Answer: c
Explanation: The \n adds a new line.

93. What is the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
a) 85.0
b) 85.1
c) 95.0
d) 95.1
View Answer

Answer: a
Explanation: Cause a decimal value of 0 to appear as output.

94. Select all options that print.


hello-how-are-you
a) print(‘hello’, ‘how’, ‘are’, ‘you’)
b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’)
d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)
View Answer

Answer: c
Explanation: Execute in the shell.

95. What is the return value of trunc()?


a) int
b) bool
c) float
d) None
View Answer
Answer: a
Explanation: Execute help(math.trunc) to get details.

96. What is the output of print 0.1 + 0.2 == 0.3?


a) True
b) False
c) Machine dependent
d) Error
View Answer

Answer: b
Explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors
from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and
0.3.

97. Which of the following is not a complex number?


a) k = 2 + 3j
b) k = complex(2, 3)
c) k = 2 + 3l
d) k = 2 + 3J
View Answer

Answer: c
Explanation: l (or L) stands for long.

98. What is the type of inf?


a) Boolean
b) Integer
c) Float
d) Complex
View Answer

Answer: c
Explanation: Infinity is a special case of floating point numbers. It can be obtained by float(‘inf’).

99. What does ~4 evaluate to?


a) -5
b) -4
c) -3
d) +3
View Answer

Answer: a
Explanation: ~x is equivalent to -(x+1).

100. What does ~~~~~~5 evaluate to?


a) +5
b) -11
c) +11
d) -5
View Answer

Answer: a
Explanation: ~x is equivalent to -(x+1).
~~x = – (-(x+1) + 1) = (x+1) – 1 = x
~~x is equivalent to x
Extrapolating further ~~~~~~x would be same as x in the final result.
In the question, x value is given as 5 and “ ~ ” is repeated 6 times. So, the correct answer for
“~~~~~~5” is 5.

101. Which of the following is incorrect?


a) x = 30963
b) x = 0x4f5
c) x = 19023
d) x = 03964
View Answer

Answer: d
Explanation: Numbers starting with a 0 are octal numbers but 9 isn’t allowed in octal numbers.

102. What is the result of cmp(3, 1)?


a) 1
b) 0
c) True
d) False
View Answer

Answer: a
Explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y.

103. Which of the following is incorrect?


a) float(‘inf’)
b) float(‘nan’)
c) float(’56’+’78’)
d) float(’12+34′)
View Answer
Answer: d
Explanation: ‘+’ cannot be converted to a float.

104. What is the result of round(0.5) – round(-0.5)?


a) 1.0
b) 2.0
c) 0.0
d) Value depends on Python version
View Answer

Answer: d
Explanation: The behavior of the round() function is different in Python 2 and Python 3. In Python
2, it rounds off numbers away from 0 when the number to be rounded off is exactly halfway through.
round(0.5) is 1 and round(-0.5) is -1 whereas in Python 3, it rounds off numbers towards nearest
even number when the number to be rounded off is exactly halfway through. See the below output.

105. How many important control structures are there in Python?


A) 3
B) 4
C) 5
D) 6
Answer: A

106. 2.elif can be considered to be abbreviation of


A) nested if
B) if..else
C) else if
D) if..elif
Answer: C

107. What plays a vital role in Python programming?


A) Statements
B) Control
C) Structure
D) Indentation
Answer: A

108. Which statement is generally used as a placeholder?


A) continue
B) break
C) pass
D) goto
Answer: C
109. The condition in the if statement should be in the form of
A) Arithmetic or Relational expression
B) Arithmetic or Logical expression
C) Relational or Logical expression
D) Arithmetic
Answer: C

110. Which is the most comfortable loop?


A) do..while
B) while
C) for
D) if..elif
Answer: C

111. What is the output of the following snippet?

i=1

while True:

if i%3 ==0: break

print(i,end='')

i +=1
A) 12
B) 123
C) 1234
D) 124
Answer: A

112. What is the output of the following snippet?

T=1

while T:

print(True)

break
A) False
B) True
C) 0
D) no output
Answer: B

113. Which amongst this is not a jump statement ?


A) for
B) goto
C) continue
D) break
Answer: A

114. Which punctuation should be used in the blank?

if <condition>_

statements-block 1

else:

statements-block 2
A) ;
B) :
C) ::
D) !
Answer: B

115. Which of the following is a Python tuple?


a) [1, 2, 3]
b) (1, 2, 3)
c) {1, 2, 3}
d) {}
View Answer

Answer: b
Explanation: Tuples are represented with round brackets.

116. Suppose t = (1, 2, 4, 3), which of the following is incorrect?


a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
View Answer
Answer: b
Explanation: Values cannot be modified in the case of tuple, that is, tuple is immutable.

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


1. >>>t=(1,2,4,3)
2. >>>t[1:3]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
View Answer

Answer: c
Explanation: Slicing in tuples takes place just as it does in strings.

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

>>>t=(1,2,4,3)
>>>t[1:-1]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
View Answer

Answer: c
Explanation: Slicing in tuples takes place just as it does in strings.

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


>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
a) [2, 3, 9]
b) [1, 2, 4, 3, 8, 9]
c) [1, 4, 8]
d) (1, 4, 8)
View Answer

Answer: c
Explanation: Execute in the shell to verify.

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

d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
View Answer

Answer: a
Explanation: Execute in the shell to verify.

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

>>>t = (1, 2)
>>>2 * t
a) (1, 2, 1, 2)
b) [1, 2, 1, 2]
c) (1, 1, 2, 2)
d) [1, 1, 2, 2]
View Answer

Answer: a
Explanation: * operator concatenates tuple.

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

>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
a) True
b) False
c) Error
d) None
View Answer

Answer: b
Explanation: Elements are compared one by one in this case.

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

>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
a) 1
b) 2
c) 5
d) Error
View Answer

Answer: d
Explanation: Tuples are immutable and don’t have an append method. An exception is thrown in
this case.

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


numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
a) 30
b) 24
c) 33
d) 12
View Answer

Answer: c
Explanation: Tuples can be used for keys into dictionary. The tuples can have mixed length and the
order of the items in the tuple is considered when comparing the equality of the keys.

125. What is the data type of (1)?


a) Tuple
b) Integer
c) List
d) Both tuple and integer
View Answer

Answer: b
Explanation: A tuple of one element must be created as (1,).

126. If a=(1,2,3,4), a[1:-1] is _________


a) Error, tuple slicing doesn’t exist
b) [2,3]
c) (2,3,4)
d) (2,3)
View Answer
Answer: d
Explanation: Tuple slicing exists and a[1:-1] returns (2,3).

127. Is the following Python code valid?

>>> a=(1,2,3)
>>> b=a.update(4,)
a) Yes, a=(1,2,3,4) and b=(1,2,3,4)
b) Yes, a=(1,2,3) and b=(1,2,3,4)
c) No because tuples are immutable
d) No because wrong syntax for update() method
View Answer

Answer: c
Explanation: Tuple doesn’t have any update() attribute because it is immutable.

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

>>> a=[(2,4),(1,2),(3,9)]
>>> a.sort()
>>> a
a) [(1, 2), (2, 4), (3, 9)]
b) [(2,4),(1,2),(3,9)]
c) Error because tuples are immutable
d) Error, tuple has no sort attribute
View Answer

Answer: a
Explanation: A list of tuples is a list itself. Hence items of a list can be sorted.

128. Which of these about a set is not true?


a) Mutable data type
b) Does not allow duplicate values
c) Data type with unordered values
d) Immutable data type
View Answer

Answer: d
Explanation: A set is a mutable data type with non-duplicate, unordered values, providing the usual
mathematical set operations.

129. Which of the following is not the correct syntax for creating a set?
a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
c) set((1,2,3,4))
d) {1,2,3,4}
View Answer

Answer: a
Explanation: The argument given for the set must be an iterable.

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


nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
a) 7
b) Error, invalid syntax for formation of set
c) 4
d) 8
View Answer

Answer: c
Explanation: A set doesn’t have duplicate items.

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

a = [5,5,6,7,7,7]
b = set(a)
def test(lst):
if lst in b:
return 1
else:
return 0
for i in filter(test, a):
print(i,end=" ")
a) 5 5 6
b) 5 6 7
c) 5 5 6 7 7 7
d) 5 6 7 7 7
View Answer

Answer: c
Explanation: The filter function will return all the values from list a which are true when passed to
function test. Since all the members of the set are non-duplicate members of the list, all of the
values will return true. Hence all the values in the list are printed.

132. Which of the following statements is used to create an empty set?


a) { }
b) set()
c) [ ]
d) ( )
View Answer

Answer: b
Explanation: { } creates a dictionary not a set. Only set() creates an empty set.

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

>>> a={5,4}
>>> b={1,2,4,5}
>>> a<b
a) {1,2}
b) True
c) False
d) Invalid operation
View Answer

Answer: b
Explanation: a<b returns True if a is a proper subset of b.

134 If a={5,6,7,8}, which of the following statements is false?


a) print(len(a))
b) print(min(a))
c) a.remove(5)
d) a[2]=45
View Answer

Answer: d
Explanation: The members of a set can be accessed by their index values since the elements of the
set are unordered.

135. If a={5,6,7}, what happens when a.add(5) is executed?


a) a={5,5,6,7}
b) a={5,6,7}
c) Error as there is no add function for set data type
d) Error as 5 already exists in the set
View Answer

Answer: b
Explanation: There exists add method for set data type. However 5 isn’t added again as set consists
of only non-duplicate elements and 5 already exists in the set. Execute in python shell to verify.
136. What will be the output of the following Python code?

>>> a={4,5,6}
>>> b={2,8,6}
>>> a+b
a) {4,5,6,2,8}
b) {4,5,6,2,8,6}
c) Error as unsupported operand type for sets
d) Error as the duplicate item 6 is present in both sets
View Answer

Answer: c
Explanation: Execute in python shell to verify.

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

>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b
a) {4,5}
b) {6}
c) Error as unsupported operand type for set data type
d) Error as the duplicate item 6 is present in both sets
View Answer
Answer: a
Explanation: – operator gives the set of elements in set a but not in set b.

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

>>> a={5,6,7,8}
>>> b={7,8,10,11}
>>> a^b
a) {5,6,7,8,10,11}
b) {7,8}
c) Error as unsupported operand type of set data type
d) {5,6,10,11}
View Answer

Answer: d
Explanation: ^ operator returns a set of elements in set A or set B, but not in both (symmetric
difference).

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


>>> s={5,6}
>>> s*3
a) Error as unsupported operand type for set data type
b) {5,6,5,6,5,6}
c) {5,6}
d) Error as multiplication creates duplicate elements which isn’t allowed
View Answer

Answer: a
Explanation: The multiplication operator isn’t valid for the set data type.

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

>>> a={5,6,7,8}
>>> b={7,5,6,8}
>>> a==b
a) True
b) False
View Answer

Answer: a
Explanation: It is possible to compare two sets and the order of elements in both the sets doesn’t
matter if the values of the elements are the same.

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

>>> a={3,4,5}
>>> b={5,6,7}
>>> a|b
a) Invalid operation
b) {3, 4, 5, 6, 7}
c) {5}
d) {3,4,6,7}
View Answer

Answer: b
Explanation: The operation in the above piece of code is union operation. This operation produces a
set of elements in both set a and set b.

142. Is the following Python code valid?

a={3,4,{7,5}}
print(a[2][0])
a) Yes, 7 is printed
b) Error, elements of a set can’t be printed
c) Error, subsets aren’t allowed
d) Yes, {7,5} is printed
View Answer

Answer: c
Explanation: In python, elements of a set must not be mutable and sets are mutable. Thus, subsets
can’t exist.

143.. A button’s caption is entered using __________


a) sentence capitalization
b) book title capitalization
c) character capitalization
d) word capitalization
View Answer

Answer: b
Explanation: Book title capitalization is a phenomenon in which the first characters of the major
words in the sentence are capitalized. A button’s caption is entered using this phenomenon

144. The text contained in the identifying label is entered using __________
a) Sentence capitalization
b) Book title capitalization
c) Character capitalization
d) Word capitalization
View Answer

Answer: a
Explanation: Sentence capitalization is a phenomenon in which the first character of every word in
the sentence should be in capital letter. The text contained in is entered using this phenomenon.

145. Each button has same height and width because they are __________ the interface.
a) Stacked
b) Queued
c) Clustered
d) Heaped
View Answer

Answer: a
Explanation: Buttons have a same height and width because they are stacked in the interface. This
property mainly copies the button, thus they get equal height and width as that of the first, which is
made with accuracy.

146. Designers usually include graphics to __________ a portion of screen.


a) Mesmerize
b) Emphasize
c) Attract
d) Glorify
View Answer

Answer: b
Explanation: The most important point the designers should keep in mind is that the graphics
should not distract the user from his/her work. Thus the graphics should be simple enough to
emphasize a portion of the screen, mainly the top left corner.

147. An object’s __________ is used to display the type, style, and size of the font, used to display
the object’s text.
a) Font property
b) Size property
c) Text property
d) Style property
View Answer

Answer: a
Explanation: An object’s font property is used to display the type, style and size of font. The type of
the font includes- regular, bold, italics or underlined. The size is 8, 10, 14, etc and the style is
‘Times new Roman’, ‘Sans Serif’ etc.

148. Designers generally avoid using __________ and __________ in an interface.


a) Italics and underline
b) Underline and bold
c) Bold and italics
d) Regular and bold
View Answer

Answer: a
Explanation: Designers generally avoid using italics and underline in a text, because they make
difficult to read; since in some font style italics is too difficult to read, and underline in some font
style looks as if an error has occurred, thus distracting the user.

149. Designers generally use __________ font style and __________ font size in an interface.
a) One, two
b) Two, one
c) Four, one
d) One, one
View Answer

Answer: a
Explanation: Designers generally use one font style in an interface because too many font sizes
make difficult to read, and distract the user. Generally, two font sizes are used one for the titles and
headings and other for the other text in the user interface.

150. __________ is generally used to emphasize the text.


a) Italics
b) Underline
c) Bold
d) Regular
View Answer

Answer: c
Explanation: Designers limit the use of bold text to titles, headings and key items to emphasize the
text.

151. Designers generally use __________ colour for the background, and __________ for the text.
a) Blue, pink
b) White, black
c) Black, white
d) Pink, blue
View Answer

Answer: b
Explanation: Designers generally use white colour for the background and black colour for the text,
because dark colour as background is hard for eyes and light colour as text may appear blurry.

152. Designers at times use colour as the means of __________ a user interface.
a) Identification
b) Charming
c) Fascinating
d) Exquisite
View Answer

Answer: a
Explanation: Designers at times want to identify a special element, using colour. But it should not
be the only means to identify an element. Each element should have an identifying level

153. A user interact with nearly all aspects of GUI with the aid of ____
(a) scanner
(b) mouse
(c) light pen
(d) joystick.

Answer: b
154. Mouse is the pointing device that interacts with nearly all aspects of the GUI. Also, keyboard.

The name of the module in Python 2.x is _____


(a) Tkinter
(b) Ubuntu
(c) float
(d) import.

Answer: A

155.. To open a file c:\scores.txt for reading, we use _____________


a) infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)
View Answer

Answer: b
Explanation: Execute help(open) to get more details.

156. To open a file c:\scores.txt for writing, we use ____________


a) outfile = open(“c:\scores.txt”, “w”)
b) outfile = open(“c:\\scores.txt”, “w”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
View Answer
Answer: b
Explanation: w is used to indicate that file is to be written to.

157. To open a file c:\scores.txt for appending data, we use ____________


a) outfile = open(“c:\\scores.txt”, “a”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
View Answer

Answer: a
Explanation: a is used to indicate that data is to be appended.

158. Which of the following statements are true?


a) When you open a file for reading, if the file does not exist, an error occurs
b) When you open a file for writing, if the file does not exist, a new file is created
c) When you open a file for writing, if the file exists, the existing file is overwritten with the new
file
d) All of the mentioned
View Answer

Answer: d
Explanation: The program will throw an error.

159. To read two characters from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
View Answer

Answer: a
Explanation: Execute in the shell to verify.

160. To read the entire remaining contents of the file as a string from a file object infile, we use
____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
View Answer

Answer: b
Explanation: read function is used to read all the lines in a file.

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

f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print(f.closed)
a) True
b) False
c) None
d) Error
View Answer

Answer: a
Explanation: The WITH statement when used with open file guarantees that the file object is closed
when the with block exits.
162. To read the next line of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
View Answer

Answer: c
Explanation: Execute in the shell to verify.
9. To read the remaining lines of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
View Answer

Answer: d
Explanation: Execute in the shell to verify.

163.. The readlines() method returns ____________


a) str
b) a list of lines
c) a list of single characters
d) a list of integers
View Answer

Answer: b
Explanation: Every line is stored in a list and returned.

164. To read the next line of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
View Answer

Answer: c
Explanation: Execute in the shell to verify.

165. To read the remaining lines of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
View Answer

Answer: d
Explanation: Execute in the shell to verify

166. The readlines() method returns ____________


a) str
b) a list of lines
c) a list of single characters
d) a list of integers
View Answer

Answer: b
Explanation: Every line is stored in a list and returned.

167. What is the use of seek() method in files?


a) sets the file’s current position at the offset
b) sets the file’s previous position at the offset
c) sets the file’s current position within the file
d) none of the mentioned
View Answer

Answer: a
Explanation: Sets the file’s current position at the offset. The method seek() sets the file’s current
position at the offset.
Following is the syntax for seek() method:
fileObject.seek(offset[, whence])
Parameters
offset — This is the position of the read/write pointer within the file.

whence — This is optional and defaults to 0 which means absolute file positioning, other values
are 1 which means seek relative to the current position and 2 means seek relative to the file’s end.

168. What is the use of truncate() method in file?


a) truncates the file size
b) deletes the content of the file
c) deletes the file size
d) none of the mentioned
View Answer

Answer: a
Explanation: The method truncate() truncates the file size. Following is the syntax for truncate()
method:
fileObject.truncate( [ size ])
Parameters
size — If this optional argument is present, the file is truncated to (at most) that size.

169. What is the current syntax of remove() a file?


a) remove(file_name)
b) remove(new_file_name, current_file_name,)
c) remove(() , file_name))
d) none of the mentioned
View Answer

Answer: a
Explanation: remove(file_name)
6. What is the current syntax of rename() a file?
a) rename(current_file_name, new_file_name)
b) rename(new_file_name, current_file_name,)
c) rename(()(current_file_name, new_file_name))
d) none of the mentioned
View Answer

Answer: a
Explanation: This is the correct syntax which has shown below.
rename(current_file_name, new_file_name)

170. Which is/are the basic I/O connections in file?


a) Standard Input
b) Standard Output
c) Standard Errors
d) All of the mentioned

Answer: d

17. Which of the following mode will refer to binary data?


a) r
b) w
c) +
d) b

Answer:d
Explanation: Mode Meaning is as explained below:
r Reading
w Writing
a Appending
b Binary data + Updating.
171. What is the pickling?
a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned
View Answer

Answer: a
. What is the correct syntax of open() function?
a) file = open(file_name [, access_mode][, buffering])
b) file object = open(file_name [, access_mode][, buffering])
c) file object = open(file_name)
d) none of the mentioned
View Answer

Answer: b

172. ___________ underlines the feature of Polymorphism in a class.


a) Virtual Function
b) Inline function
c) Enclosing class
d) Nested class
View Answer

Answer: a

173. Which feature in OOP is used to allocate additional functions to a predefined operator in any
language?
a) Function Overloading
b) Function Overriding
c) Operator Overloading
d) Operator Overriding
View Answer

Answer: c
Explanation: The feature is operator overloading. There is not a feature named operator overriding
specifically. Function overloading and overriding doesn’t give addition function to any operator.

174. Which feature can be implemented using encapsulation?


a) Polymorphism
b) Overloading
c) Inheritance
d) Abstraction
View Answer
Answer: d
Explanation: Data abstraction can be achieved by using encapsulation. We can hide the operation
and structure of actual program from the user and can show only required information by the user.

175. Which of these definitions correctly describes a module?


a) Denoted by triple quotes for providing the specification of certain program elements
b) Design and implementation of specific functionality to be incorporated into a program
c) Defines the specification of how it is to be used
d) Any program that reuses code
View Answer

Answer: b
Explanation: The term “ module ” refers to the implementation of specific functionality to be
incorporated into a program.

176.. Which of the following is not an advantage of using modules?


a) Provides a means of reuse of program code
b) Provides a means of dividing up tasks
c) Provides a means of reducing the size of the program
d) Provides a means of testing individual parts of the program
View Answer

Answer: c
Explanation: The total size of the program remains the same regardless of whether modules are
used or not. Modules simply divide the program.

177. Program code making use of a given module is called a ______ of the module.
a) Client
b) Docstring
c) Interface
d) Modularity
View Answer

Answer: a
Explanation: Program code making use of a given module is called the client of the module. There
may be multiple clients for a module.

178. ______ is a string literal denoted by triple quotes for providing the specifications of certain
program elements.
a) Interface
b) Modularity
c) Client
d) Docstring
View Answer

Answer: d
Explanation: Docstring used for providing the specifications of program elements.

179. Which of the following is true about top-down design process?


a) The details of a program design are addressed before the overall design
b) Only the details of the program are addressed
c) The overall design of the program is addressed before the details
d) Only the design of the program is addressed
View Answer

Answer: c
Explanation: Top-down design is an approach for deriving a modular design in which the overall
design.
Participate in Python Programming Certification Contest of the Month Now!

180. In top-down design every module is broken into same number of submodules.
a) True
b) False
View Answer

Answer: b
Explanation: In top-down design every module can even be broken down into different number of
submodules.

181. All modular designs are because of a top-down design process.


a) True
b) False
View Answer

Answer: b
Explanation: The details of the program can be addressed before the overall design too. Hence, all
modular designs are not because of a top-down design process

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

#mod1
def change(a):
b=[x*2 for x in a]
print(b)
#mod2
def change(a):
b=[x*x for x in a]
print(b)
from mod1 import change
from mod2 import change
#main
s=[1,2,3]
change(s)
a) [2,4,6]
b) [1,4,9]
c)[2,4,6][1,4,9]
d) There is a name clash
View Answer

Answer: d
Explanation: A name clash is when two different entities with the same identifier become part of
the same scope. Since both the modules have the same function name, there is a name clash.

183. Which of the following isn’t true about main modules?


a) When a python file is directly executed, it is considered main module of a program
b) Main modules may import any number of modules
c) Special name given to main modules is: __main__
d) Other main modules can import main modules
View Answer

Answer: d
Explanation: Main modules are not meant to be imported into other modules.

184. Which of the following is not a valid namespace?


a) Global namespace
b) Public namespace
c) Built-in namespace
d) Local namespace
View Answer

Answer: b
Explanation: During a Python program execution, there are as many as three namespaces –
built-in namespace, global namespace and local namespace.

185. Which of the following is false about “import modulename” form of import?
a) The namespace of imported module becomes part of importing module
b) This form of import prevents name clash
c) The namespace of imported module becomes available to importing module
d) The identifiers in module are accessed as: modulename.identifier
View Answer
Answer: a
Explanation: In the “import modulename” form of import, the namespace of imported module
becomes available to, but not part of, the importing module.

186. Which of the following is false about “from-import” form of import?


a) The syntax is: from modulename import identifier
b) This form of import prevents name clash
c) The namespace of imported module becomes part of importing module
d) The identifiers in module are accessed directly as: identifier
View Answer

Answer: b
Explanation: In the “from-import” form of import, there may be name clashes because names of
the imported identifiers aren’t specified along with the module name.

187. Which of the statements about modules is false?


a) In the “from-import” form of import, identifiers beginning with two underscores are private and
aren’t imported
b) dir() built-in function monitors the items in the namespace of the main module
c) In the “from-import” form of import, all identifiers regardless of whether they are private or
public are imported
d) When a module is loaded, a compiled version of the module with file extension .pyc is
automatically produced
View Answer

Answer: c
Explanation: In the “from-import” form of import, identifiers beginning with two underscores are
private and aren’t imported.

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

from math import factorial


print(math.factorial(5))
a) 120
b) Nothing is printed
c) Error, method factorial doesn’t exist in math module
d) Error, the statement should be: print(factorial(5))
View Answer

Answer: d
Explanation: In the “from-import” form of import, the imported identifiers (in this case factorial())
aren’t specified along with the module name.

189. What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the global namespace, then the local namespace and finally the built-in
namespace
b) Python first searches the local namespace, then the global namespace and finally the built-in
namespace
c) Python first searches the built-in namespace, then the global namespace and finally the local
namespace
d) Python first searches the built-in namespace, then the local namespace and finally the global
namespace
View Answer

Answer: b
Explanation: Python first searches for the local, then the global and finally the built-in namespace.

190. Python modules are stored in which type of file?


a).txt file
b).md file
c).py file
d).python file
Answer: C

Any text file with the .py extension containing Python code is basically a module. Different Python
objects such as functions, classes, variables, constants, etc., defined in one module can be made
available to an interpreter session or another Python script by using the import statement. Learn
modules in Python.

191. Which of these is not a built-in module in Python distribution?


a)math
b)os
c)random
d)pi
Answer: D

Others are modules in the standard library. Pillow is a third-party imaging library that needs to be
installed explicitly. Learn built-in modules in Python.

192. Built-in modules in Python are written in


a)C
b)C++
c)Python
d)Java
Answer: A

The standard reference implementation of Python is written in C. Hence, the built-in modules are
integrated with the Python interpreter because they are written in C.
193. What will print (randrange(1,10)) statement do?
a)Prints numbers from 1 to 10
b)Print numbers 1 to 10 in random order
c)Prints any one number from 1 to 9 selected randomly
d)Print numbers from 1 to 9

Answer: C
The randrange() function returns one random number from the list.

194. Which of the following statement is incorrect?


a)log() function returns natural logarithm of a number
b)log10() function returns the standard logarithm of a number
c)log10() function returns log value of 10
d)all statements are incorrect
Answer: C
The log10() function returns the standard logarithm (base 10) of a given number and a log value of
10

: The following is an example of _________

def getcol(x):
for i in range(x):
yield i
a)Void Function
b)Generator function
c)Iterator function
d)Yield function
Answer: B
Python provides a generator to create your own iterator function. A generator is a special type of
function which does not return a single value; instead, it returns an iterator object with a sequence
of values. In a generator function, a yield statement is used rather than a return statement. The
following is a simple generator function. Learn generator function.

194. The dir() function in Python results in _________.


a)List of all files in a folder
b)List of all functions in a module
c)List of all modules in a package
d)None of these
Answer: B

The dir() function is different from the dir command in windows. It returns the list of attributes and
functions in a module.

195. Which of the following is true about the Python package?


a)A package is a collection of modules.
b)Name of package corresponds to name of the folder containing modules
c)The folder must contain __init__.py file
d)All of the above
Answer: D
Python recognizes any folder with one or more Python modules in addition to __init__.py file as a
package

196. Which of the following can be a part of the Python module?


a)Function
b)Class
c)Variables
d)All of the above
Answer: D

197. Which of the following is not a module attribute?


a)__file__
b)__name__
c)__dict__
d)__list__
Answer : D

The other three options are module attributes returning the name of .py file, name, and path of
module and dictionary of attributes, functions, and other definitions with values, respectively.

197. Which of the following is an incorrect syntax?


a)import function from module
b)from module import function
c)import module
d)None of the above
Answer: A

198 . The dir() function in Python results in _________.


a)List of all files in a folder
b)List of all functions in a module
c)List of all modules in a package
d)None of these
Answer: B

The dir() function is different from the dir command in windows. It returns the list of attributes and
functions in a module
For more info
08102585379

You might also like