1. Who developed Python Programming Language?
a) Wick van Rossum b) Rasmus Lerdorf c) Guido van Rossum d) Niene Stom
2. What will be the value of the following Python expression?
print(4 + 3 % 5)
a) 7 b) 2 c) 4 d) 1
3. 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) SyntaxError c) 1 2 d) none of the mentioned
4. 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
5.Python supports the creation of anonymous functions at runtime, using a construct called _______
a) pi b) anonymous c) lambda d) none of the mentioned
6.What are the values of the following Python expressions?
print(2**(3**2))
print((2**3)**2)
print(2**3**2)
a) 512, 64, 512 b) 512, 512, 512 c) 64, 512, 64 d) 64, 64, 64
7.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
8.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
9.What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]:
print(i, end=' ')
a) 4 3 2 1 b) error c) 1 2 3 4 d) none of the mentioned
10. Which function is called when the following Python program is executed?
f = foo()
format(f)
a) str() b) format() c) __str__() d) __format__()
11. 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
12. Which of the following statements is used to create an empty set in Python?
a) ( ) b) [ ] c) { } d) set()
13. 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]
14. 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]
15. 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 d) none of the mentioned
b) c)
0 0
1 1
2 2
3
16. 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
17. 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
18. What is defined as a set of code used to carry out specific tasks ?
a. function b. class c. loop d. none of the above
19. A linked list a linear collection of similar data elements called ______ .
a. Subscript b. Index c. Nodes d. Null
20.What will be the output of the following Python code?
y = 6
z = lambda x: x * y
print (z(8))
a) 48 b) 14 c) 64 d) None of the mentioned
21.What will be the output of the following Python code?
min = (lambda x, y: x if x < y else y)
print(min(101*99, 102*98))
a) 9997 b) 9999 c) 9996 d) None of the mentioned
22. What is a variable defined outside a function referred to as?
a) A static variable b) A global variable c) A local variable d) An automatic variable
23. What will be the output of the following Python code?
def a(b):
b = b + [5]
c = [1, 2, 3, 4]
a(c)
print(len(c))
a) 4 b) 5 c) 1 d) An exception is thrown
24. What will be the output of the following Python code?
def change(one, *two):
print(type(two))
change(1,2,3,4)
a) Integer b) <class ‘tuple’> c) <class ‘Dict’> d) An exception is thrown
25. Which of the following data structures is returned by the functions globals() and locals()?
a) list b) set c) dictionary d) tuple
26.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}
27.What will be the output of the following Python code?
l=list('HELLO')
p=l[0], l[-1], l[1:3]
print('a={0}, b={1}, c={2}'.format(*p))
a) Error
b) “a=’H’, b=’O’, c=(E, L)”
c) “a=H, b=O, c=[‘E’, ‘L’]”
d) Junk value
28. What will be the output of the following Python code?
x = [12, 34]
print(len(list(map(len, x))))
a) 2
b) 1
c) error
d) none of the mentioned
29. 24. What is the purpose of the filter() function?
a) To apply a function to each element of a list
b) To filter elements from a list
c) To reduce a list to a single value
d) To sort a list
30 What is the purpose of the issubset() method?
a) To check if a set is a subset of another set
b) To check if a set is a superset of another set
c) To check if two sets are equal
d) To sort a set
31. What is the purpose of the sys module?
a)File I/O operations
b)System-specific parameters and functions
c)Mathematical operations
d)Web development
32. Which module is commonly used for working with regular expressions?
a)math
b)re
c)os
d)datetime
33. hat doesthe random.choice() function do?
a)Generates a random integer
b)Picks a random element from a sequence
c)Sorts a list in random order
d)Returns a random floating-point number
34.
35
36.
37.
38. Which module in Python is commonly used for working with regular expressions but has a simpler
API compared to re?
a)Regex b)regexp c)relib d)regexlib
39.
40.
41Which method adds an element to the end of a list?
A) append() B) add() C) push() D) insert()
42.What does list1 = list2 do?
A) Creates a copy B) Creates an alias C) Clones the list D) None
43.Tuples & Dictionaries
Tuples are:
A) Mutable B) Immutable
44.What does next() do on an iterator?
A) Returns next element B) Restarts iteration C) Ends loop D) None
45.What will be printed?
def f(): yield 1 yield 2 print(list(f()))
A) [1, 2] B) (1, 2) C) 1 2 D) None
46
47.Which module in Python is used for working with network-related tasks, such as creating and
handling sockets?
A)network b)socketlib c)net d)socket
48.What does the itertools.cycle() function do?
A)Creates an infinite iterator from a finite iterable
B)Generates all possible permutations of an iterable
C)Repeats an iterable indefinitely
D)Filters elements based on a predicate function
49.
51
68.