Skip to content

Instantly share code, notes, and snippets.

@etiennecl
Last active November 24, 2020 21:59
Show Gist options
  • Save etiennecl/a9c3a7ccb6f5b50e98725c5482e954cc to your computer and use it in GitHub Desktop.
Save etiennecl/a9c3a7ccb6f5b50e98725c5482e954cc to your computer and use it in GitHub Desktop.
Skills Test Python

Skills Test Python

The first part is a set of technical questions related to fundamental knowledge of python.

Fundammental Questions

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)
  1. shuffle the elements for the no. of times equal to the size of the list.
  2. shuffle the elements of the list in-place.
  3. It'll not modify the list. This function is just a placeholder and yet to be implemented.
  4. return a list where elements 10, 20 and 30 would be at random positions.

Question 2: Which of the following is the output of the Python code fragment given below?

var1 = 4.5
var2 = 2
print(var1//var2)
  1. 22.5
  2. 2.25
  3. 2.5
  4. 2.0
  5. 20.0

Question 3: Which of the following is the output of the below Python code?

def myfunc():
 try:
  print('Monday')
 finally:
  print('Tuesday')
myfunc()
  1. Tuesday
  2. Monday
  3. None of these
  4. undefined exception
  5. Monday Tuesday
  6. Tuesday Monday

Question 4: Which of the following is the correct output of the call to below line of code?

print(list("hello"))
  1. ['h', 'e', 'l', 'l', 'o']
  2. [h,e,l,l,o]
  3. hello
  4. ['h' 'e' 'l' 'l' 'o']
  5. None of these

Question 5: Which of the following is the output of the below Python code?

var1 = lambda var: var * 2
ret = lambda var: var * 3
result = 2
result = var1(result)
result = ret(result)
result = var1(result)
print(result)
  1. 7
  2. 36
  3. 12
  4. 24
  5. 48

Question 6: Which of the following is the output of the below Python code snippet?

ints = set([1,1,2,3,3,3,4])
print(len(ints))
  1. 7
  2. 1
  3. 4
  4. 5

Question 7: Which of the following statements would create an instance of Ubuntu class correctly?

class Ubuntu:
 def __init__(self, ramsize):
  self.ram = ramsize
  self.type = 'server'
  1. Ubuntu = Ubuntu(2000)
  2. Ubuntu = Ubuntu('client', 2000)
  3. None of these
  4. Ubuntu = Ubuntu()
  5. Ubuntu = Ubuntu('server', 2000)

Question 8: Which of the following for loops would yield the below number pattern?

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)

Question 9: Determine the output of the below Python code fragment?

var1 = True
var2 = False
var3 = False

if var1 or var2 and var3:
 print("True")
else:
 print("False")
  1. Compile time error
  2. False
  3. True
  4. Runtime error
  5. None of these

Question 10: Which of the following correctly describes the output of the below Python code?

testArr = [11, 22, 33, 22, 11] 
result = testArr[0] 
for iter in testArr: 
 if iter > result: 
  result = iter
print(result)
  1. result is the average of all the number in the list.
  2. result is the smallest number in the list.
  3. result is the sum of all the number in the list.
  4. None of these
  5. result is the largest number in the list.

Question 11: Which of the following is the output of the below Python code?

mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
print(mylist[:-1])
  1. aaaaaabbb
  2. [a, aa, aaa, b, bb]
  3. ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
  4. ['a', 'aa', 'aaa', 'b', 'bb']
  5. Error
  6. None of the mentioned

Question 12: Which of the following is the output of the below Python code?

mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
print(mylist[int(-1/2)])
  1. aaa
  2. a
  3. 'bbb'
  4. None of the mentioned
  5. bbb
  6. b
  7. bb

Question 13: Which of the following is the output of the instructions mentioned below?

def test1(param):
 return str(param)

def test2(param):
 return str(2 * param)

result = test1(1) + test2(2)
print(result)
  1. 3
  2. 14
  3. Compile time error
  4. 5

Question 14: Which of the following is the output of the lines of code specified below?

x = 1
print(++++x)
  1. 3
  2. 2
  3. 4
  4. 1

Question 15: Which of the following is the output of the below piece of code?

import random
print(random.seed(3))
  1. 3
  2. None of the mentioned
  3. Error
  4. Null
  5. None

Question 16: Which of the following is the output of the below Python code?

def test():
 try:
  return 1
 finally:
  return 2
result = test()
print(result)
  1. 2
  2. Runtime error.
  3. Compile error, there is more than one return statement in a single try-finally block.
  4. 1
  5. None of these

Question 17: Which of the following is the output of the below Python code?

def test1(param):
 return param

def test2(param):
 return param * 2

def test3(param):
 return param + 3

result = test1(test2(test3(1)))
print(result)
  1. 8
  2. 6
  3. 3
  4. 1

Question 18: Which of the following is the output of the code given below?

mylist=['abc','cde','abcde','efg']
print(max(mylist))
  1. efg
  2. abcde
  3. abc
  4. cde
  5. "abcde"
  6. 'abcde'

Question 19: Which of the following is the output of the below Python code?

try:
 if '1' != 1:
  raise "firstError"
 else:
  print("firstError has not occured")
except "firstError":
 print("firstError has occured")
  1. firstError has not occured
  2. firstError has occured
  3. ValueError occurs
  4. TypeError occurs

Question 20: Which of the following is the output of the instructions given below?

mylist=[1, 5, 9, int('0')]
print(sum(mylist))
  1. 63
  2. 16
  3. 15
  4. 5
  5. 1
  6. None of the mentioned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment