1. What will be the output of the following
Python code?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
Correct : D. o
2. What arithmetic operators cannot be used with strings?
Correct : C. –
3. What will be the output of the following Python code?
>>>print (r"\nhello")
Correct : B. \\nhello
4. What will be the output of the following Python code?
>>>print('new' 'line')
Correct : C. newline
5. What will be the output of the following
Python code?
1. >>>str1="helloworld"
2. >>>str1[::-1]
Correct : A. dlrowolleh
6. What will be the output of the following
Python code?
print(0xA + 0xB + 0xC)
Correct : D. 33
7. What will be the output of the following
Python code?
1. class father:
2. def __init__(self, param):
3. self.o1 = param
4.
5. class child(father):
6. def __init__(self, param):
7. self.o2 = param
8.
9. >>>obj = child(22)
10. >>>print "%d %d" % (obj.o1, obj.o2)
Correct : D. error is generated
8. What will be the output of the following
Python code?
1. class tester:
2. def __init__(self, id):
3. self.id = str(id)
4. id="224"
5.
6. >>>temp = tester(12)
7. >>>print(temp.id)
Correct : C. 12
9. 3. What will be the output of the following
Python code?
1. >>>example = "snow world"
2. >>>print("%s" % example[4:7])
Correct : A. wo
10. What will be the output of the following
Python code?
1. >>>example = "snow world"
2. >>>example[3] = 's'
3. >>>print example
Correct : C. error
11. >>>max("what are you")
Correct : D. y
12. Given a string example=”hello” what is the output of example.count(‘l’)?
Correct : A. 2
13. >>>example.find("e")
Correct : C. 1
14. >>>example.rfind("e")
Correct : B. 4
15. >>>example[::-1].startswith("d")
Correct : B. true
16. To concatenate two strings to a third what statements are applicable?
Correct : C. s3 = s1. add (s2)
17. >>>chr(ord('A'))
Correct : A. a
18. >>>print(chr(ord('b')+1))
Correct : C. c
19. Which of the following statement prints hello\example\test.txt?
Correct : B. print(“hello\\example\\test.txt”)
20. Suppose s is “\t\tWorld\n”, what is s.strip()?
Correct : D. world
21. The format function, when applied on a string returns
Correct : D. str
22. +2+3?
Correct : C. error
23. >>>print("A", end = ' ')
Correct : C. d c b a
24. What will be displayed by print(ord(‘b’) – ord(‘a’))?
Correct : B. 1
25. Say s=”hello” what will be the return value of type(s)?
Correct : C. str
26. What is “Hello”.replace(“l”, “e”)?
Correct : A. heeeo
27. To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
Correct : C. s. getitem (3)
28. To return the length of string s what command do we execute?
Correct : A. s. len ()
29. If a class defines the str (self) method, for an object obj for the class, you can use which command to invoke the str method.
Correct : D. all of the mentioned
30. To check whether string s1 contains another string s2, use
Correct : A. s1. contains (s2)
31. Suppose i is 5 and j is 4, i + j is same as
Correct : B. i. add (j)
32. print(id(s1) == id(s2))
Correct : C. false true
33. What function do you use to read a string?
Correct : A. input(“enter a string”)
34. ), '*', sep= '')
Correct : D. * abcdef*
35. , 1))
Correct : D. error
36. , '1'))
Correct : A. 1abcdef
37. , '12'))
Correct : D. error
38. , 11))
Correct : B. 0
39. What is the default value of encoding in encode()?
Correct : C. utf-8
40. } and {1}".format('foo', 'bin'))
Correct : A. hello foo and bin
41. } and {0}".format('bin', 'foo'))
Correct : A. hello foo and bin
42. } and {name2}".format( 'foo', 'bin'))
Correct : C. error
43. !r} and {0!s}".format('fo o', 'bin'))
Correct : B. hello ‘foo’ and foo
44. } and {1}".format(('foo', 'bin')))
Correct : C. error
45. [0]} and {0[1]}".format(( 'foo', 'bin')))
Correct : A. hello foo and bin
46. , 10, 12))
Correct : A. the sum of 2 and 10 is 12
47. , 10, 12))
Correct : B. the sum of 10 and a is 14
48. 2223334))
Correct : A. 1,112,223,334
49. 2223334'))
Correct : D. error
50. 2223334))
Correct : D. error
51. 2223334))
Correct : C. 1112223334
52. :.2}'.format(1/3))
Correct : B. 0.33
53. :.2%}'.format(1/3))
Correct : C. 33.33%
54. '.isalnum())
Correct : A. true
55. '.isalnum())
Correct : B. false
56. xa'.isdigit())
Correct : B. false
57. ,'.islower())
Correct : A. true
58. '.isnumeric())
Correct : A. true
59. 1'.isnumeric())
Correct : B. false
60. erdE a'.isprintable())
Correct : A. true
61. '.replace('cd', '12'))
Correct : A. ab12ef12
62. : 100}))
Correct : D. none of the mentioned
63. '.zfill(5))
Correct : C. +0099
64. Which of the following functions is a built- in function in python?
Correct : D. print()
65. 576)
Correct : B. 5
66. 5676,2)?
Correct : C. 4.57
67. ,0,4.2)
Correct : C. error
68. ,-4), 2,7)
Correct : B. false
69. +2j)
Correct : D. 1+2j
70. What is the output of the function complex()?
Correct : A. 0j
71. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
Correct : B. (a//b, a%b)
72. The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid.
Correct : A. true
73. Which of the following functions does not necessarily accept only iterables as arguments?
Correct : C. chr()
74. Which of the following functions accepts only integers as arguments?
Correct : C. chr()
75. Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
Correct : D. list(reversed(l))
76. Which of the following functions will not result in an error when no arguments are passed to it?
Correct : D. float()
77. Which of the following functions does not throw an error?
Correct : B. ord(‘ ‘)
78. Which of the following is the use of function in python?
Correct : A. functions are reusable pieces of programs
79. printMax(3, 4)
Correct : C. 4 is maximum
80. print(maximum(2, 3))
Correct : B. 3
81. Which of the following is a feature of DocString?
Correct : D. all of the mentioned
82. What are the two main types of functions?
Correct : B. built-in function & user defined function
83. Where is function defined?
Correct : D. all of the mentioned
84. Which of the following is the use of id() function in python?
Correct : A. id returns the identity of the object
85. Which of the following refers to mathematical function?
Correct : A. sqrt
86. print x
Correct : C. 27
87. Python supports the creation of anonymous functions at runtime, using a construct called
Correct : A. lambda
88. print z(8)
Correct : A. 48
89. Does Lambda contains return statements?
Correct : B. false
90. Lambda is a statement.
Correct : B. false
91. What is a variable defined outside a function referred to as?
Correct : B. a global variable
92. What is a variable defined inside a function referred to as?
Correct : C. a local variable
93. , i = 2)
Correct : D. 3 2
94. ,2,3,4)
Correct : B. tuple
95. If a function doesn’t have a return statement, which of the following does the function return?
Correct : C. none
96. ',B='2')
Correct : C. dictionary
97. What is the type of each element in sys.argv?
Correct : D. string
98. What is the length of sys.argv?
Correct : B. number of arguments + 1
99. How many keyword arguments can be passed to a function in a single function call?