1. What are wxPython, pyQT, and pyGTK?
2. It is possible to create a while loop that will never stop?
3. What does the expression string1 + string2 do?
4. there is a code example: x = {'quizful': []} How can you add an element 'python test' in list 'quizful'?
5. PEP8 style guidelines include:
6. Where does 'pip install' retrieve modules from?
7. A decorator in python ________
8. What does mro stand for in Python?
9. What is a DBM in Python?
10. Which is a valid class declaration?
11. What is htmllib?
12. What gets printed: a = b = [1, 2, 3] b[2] = 4 print(a)
13. What is a pickle?
14. What is the difference between using list comprehensions and generator expressions?
15. What is printed by the following: print type(lambda:None) ?
16. What is the default SimpleHTTPServer port?
17. In Python, what does the 'dir' builtin do?
18. consider next code import asyncio @asyncio.coroutine def foo1(): yield from asyncio.sleep(3.0) print('1') @asyncio.coroutine def foo2(): yield from asyncio.sleep(1.0) print('2') @asyncio.coroutine def foo3(): print('3') @asyncio.coroutine def test(): asyncio.async(foo1()) asyncio.async(foo2()) asyncio.async(foo3()) yield from asyncio.sleep(2.0) loop.stop() loop = asyncio.get_event_loop() asyncio.async(test()) loop.run_forever() loop.close() What will be printed first?
19. class Foo(object): def bar(self, x): pass foo = Foo() is foo.bar and foo.bar.__func__ is the same object?
20. Which word is standard library functions? apply, complex, has, min, setaddr
21. consider we have class Foo(object): def bar(self): pass foo = Foo() How i can get reference to instance from foo.bar
22. In Python, what is the default maximum level of recursion?
23. Which function can change the maximum level of recursion?
24. Which is the best method to find the indices of all occurances of a word in a string? line = 'mary had a little lamb, little lamb, little lamb' word = 'lamb'
25. Which is the correct syntax for Python dictionary comprehension?
26. In the following code, what will be printed ? class parent: def __init__(self, param): self.v1 = param class child(parent): def __init__(self, param): self.v2 = param obj = child(5) print '%d %d' % (obj.v1, obj.v2)
27. Output of the below code snippet? x = 10 def foo(): print(x) x = x - 1 foo() print(x)
28. The output of executing string.ascii_letters can also be achieved by ____?
29. Which one is reentrant lock type?
30. What is the method to retrieve the list of all active thread objects?
31. Which function immediately terminates the program?
32. Output of following code? var1 = lambda var: var * 2 ret = lambda var: var * 2 result = 3 result = var1(result) result = ret(result) result = var1(result) print(result)
33. In Python 3.4.2, which symbol is used for writing a comment?
34. This question is based on the graphic shown below. Choose the correct output of the given Python code.
35. Which Python/C API functions will NOT always return NULL?
36. Output of the following program? i = [12, 9, 14] k = [7, 16, 11] for j in i[:]: for m in k[:]: if(j%m == 0): j = j // 2 m = m / 2 print (j, m) else: j = j + m m = m - j print (j, m)
37. Output of the following program? def country(*abc): if len(abc) == 1: item = abc[0] def f(obj): return obj[item] else: def f(obj): return tuple(obj[item] for item in abc) return f selection = [] selection = country(slice(2, None))('AUSTRALIA') print (selection)
38. In which mode of files, the 'tell()' function returns an opaque number that gives the current position of the file object?
39. This question is based on the graphic shown below. What will be the output of the given Python code?
40. Which shell expression will give the result as an integer value? 1. >>> (100 - 4 x 5) / (20 - 2 x 5) 2. >>> 7.0 / 4 3. >>> 5 / 4 4. >>> 2 x 4 / 2 5. >>> 5 - 2
41. Which option is a correct syntax of the 'AttlistDeclHandler' method?
42. While working in Python 3.4, sockets are by default created in the _______ mode.
43. Which two of the following shell expressions in Python 3.4.2 will give syntax error? 10 * (1/0); 2 + char *3; while True print('Python'); print('4') + print('4'); while False; print('Python'); What will be the output of the below-given code in Python 3.4.2 shell? >>>str = 'example123' >>>str[::-1]
44. During the execution of the below-given Python/C API function, what will happen when no exception has been raised? int PyErr_ExceptionMatches(PyObject *exc)
45. Which option is not a server socket method?
46. Following exceptions is raised when the sequence subscript is out of range?
47. Which Python 3.4.2 shell expressions will produce the below-given output? 56.25
48. Output of the following line of code in Python 3.4.2? >>>print (0xD + 0xB + 0xC)
49. In Python 3.4, a conventional pluggable event loop model is provided by which library modules?
50. Otput of the following expression in Python 3.4 shell? '-6.34'.zfill(7)
51. Which expression in Python 3.4 will give an error?
52. Output of the following Python code : class Ba(object): pass class De(Ba): pass print(issubclass(De. Ba)) print(issubclass(Ba, De)) d = 090 b = 880 print(isinstance(b, De)) print(isinstanceld. 88))
53. Which tuples are not used in the AF_INET6 address family?
54. Which two interface objects cannot have child nodes?
55. Which option are the correct general socket methods?
56. Which two dictionary objects return '0' on success and '-1'on failure?
57. What is one of the most common use of Python's sys library?
58. What is an instance method?
59. What built-in Python data type is best suited for implementing a queue?
60. What does a class's __init__() method do?
61. What is the correct syntax for creating a variable that is bound to a dictionary?
62. What will happen if you use a while loop and forget to include logic that eventually causes the while loop to stop?
63. What is the correct syntax for adding a key called variety to the fruit_info dictionary that has a value of Red Delicious?
64. Which command will create a list from 10 down to 1? Example:10,9,8,7,6,5,4,3,2,1
65. Which mode is not a valid way to access a file from within a Python script?
66. What will be the output of this code? [1,2,3] * 3
67. Given a list defined as numbers = [1,2,3,4], what is the value of numbers[-2]?
Python MCQs | Topic-wise