The first part is a set of technical questions related to fundamental knowledge of python.
Question 1: Which of the following statements best describes the behavior of the random.shuffle(mylist) as being used in the below code fragment?
import random
mylist = [10, 20, 30]
random.shuffle(mylist)
print(mylist)
- shuffle the elements for the no. of times equal to the size of the list.
- shuffle the elements of the list in-place.
- It'll not modify the list. This function is just a placeholder and yet to be implemented.
- return a list where elements 10, 20 and 30 would be at random positions.
var1 = 4.5
var2 = 2
print(var1//var2)
- 22.5
- 2.25
- 2.5
- 2.0
- 20.0
def myfunc():
try:
print('Monday')
finally:
print('Tuesday')
myfunc()
- Tuesday
- Monday
- None of these
- undefined exception
- Monday Tuesday
- Tuesday Monday
print(list("hello"))
- ['h', 'e', 'l', 'l', 'o']
- [h,e,l,l,o]
- hello
- ['h' 'e' 'l' 'l' 'o']
- None of these
var1 = lambda var: var * 2
ret = lambda var: var * 3
result = 2
result = var1(result)
result = ret(result)
result = var1(result)
print(result)
- 7
- 36
- 12
- 24
- 48
ints = set([1,1,2,3,3,3,4])
print(len(ints))
- 7
- 1
- 4
- 5
class Ubuntu:
def __init__(self, ramsize):
self.ram = ramsize
self.type = 'server'
- Ubuntu = Ubuntu(2000)
- Ubuntu = Ubuntu('client', 2000)
- None of these
- Ubuntu = Ubuntu()
- Ubuntu = Ubuntu('server', 2000)
11111
22222
33333
44444
55555
for i in range(1, 6):
print(str(i) * 5)
for i in range(0, 5):
print(str(i) * 5)
for i in range(1, 6):
print(i, i, i, i, i)
for i in range(1, 5):
print(str(i) * 5)
var1 = True
var2 = False
var3 = False
if var1 or var2 and var3:
print("True")
else:
print("False")
- Compile time error
- False
- True
- Runtime error
- None of these
testArr = [11, 22, 33, 22, 11]
result = testArr[0]
for iter in testArr:
if iter > result:
result = iter
print(result)
- result is the average of all the number in the list.
- result is the smallest number in the list.
- result is the sum of all the number in the list.
- None of these
- result is the largest number in the list.
mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
print(mylist[:-1])
- aaaaaabbb
- [a, aa, aaa, b, bb]
- ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
- ['a', 'aa', 'aaa', 'b', 'bb']
- Error
- None of the mentioned
mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
print(mylist[int(-1/2)])
- aaa
- a
- 'bbb'
- None of the mentioned
- bbb
- b
- bb
def test1(param):
return str(param)
def test2(param):
return str(2 * param)
result = test1(1) + test2(2)
print(result)
- 3
- 14
- Compile time error
- 5
x = 1
print(++++x)
- 3
- 2
- 4
- 1
import random
print(random.seed(3))
- 3
- None of the mentioned
- Error
- Null
- None
def test():
try:
return 1
finally:
return 2
result = test()
print(result)
- 2
- Runtime error.
- Compile error, there is more than one return statement in a single try-finally block.
- 1
- None of these
def test1(param):
return param
def test2(param):
return param * 2
def test3(param):
return param + 3
result = test1(test2(test3(1)))
print(result)
- 8
- 6
- 3
- 1
mylist=['abc','cde','abcde','efg']
print(max(mylist))
- efg
- abcde
- abc
- cde
- "abcde"
- 'abcde'
try:
if '1' != 1:
raise "firstError"
else:
print("firstError has not occured")
except "firstError":
print("firstError has occured")
- firstError has not occured
- firstError has occured
- ValueError occurs
- TypeError occurs
mylist=[1, 5, 9, int('0')]
print(sum(mylist))
- 63
- 16
- 15
- 5
- 1
- None of the mentioned