Python 3
Python 3
Full marks:60
advertisement
4 + 3 % 5
a) 7
b) 2
c) 4
d) 1
10. Which of the following character is used to give single-line comments in Python?
a) //
b) #
c) !
d) /*
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
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
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
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
2**(3**2)
(2**3)**2
2**3**2
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
min(max(False,-3,-4), 2,7)
a) -4
b) -3
c) 2
d) False
25. Which of the following is not a core data type in Python programming?
a) Tuples
b) Lists
c) Class
d) Dictionary
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
len(["hello",2, 4, 6])
a) Error
b) 6
c) 4
d) 3
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
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
31. What will be the output of the following Python code snippet?
a) 4 3 2 1
b) error
c) 1 2 3 4
d) none of the mentioned
1.>>>"a"+"bc"
a) bc
b) abc
c) a
d) bca
33. Which function is called when the following Python program is executed?
f = foo()
format(f)
a) str()
b) format()
c) __str__()
d) __format__()
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)
a) 12
b) 224
c) None
d) Error
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
37. Which module in the python standard library parses options received from the command
line?
a) getarg
b) getopt
c) main
d) os
z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
z
print("abc. DEF".capitalize())
a) Abc. def
b) abc. def
c) Abc. Def
d) ABC. DEF
41. Which of the following statements is used to create an empty set in Python?
a) ( )
b) [ ]
c) { }
d) set()
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
a) * abcde *
b) *abcde *
c) * abcde*
d) * abcde *
1.>>>list1 = [1, 3]
2.>>>list2 = list1
3.>>>list1[0] = 4
4.>>>print(list2)
a) [1, 4]
b) [1, 3, 4]
c) [4, 3]
d) [1, 3]
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]
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
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
1.def addItem(listParam):
2. listParam += [1]
3.
4.mylist = [1, 2, 3, 4]
5.addItem(mylist)
6.print(len(mylist))
a) 5
b) 8
c) 2
d) 1
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
round(4.576)
a) 4
b) 4.6
c) 5
d) 4.5
x = [[0], [1]]
print((' '.join(list(map(str, x))),))
a) 01
b) [0] [1]
c) (’01’)
d) (‘[0] [1]’,)