Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. What will be the output of the following Python code? >>> import collections >>> a=dict() >>> a=collections.defaultdict(int) >>> a[1] a) 1 b) 0 c)

1. What will be the output of the following Python code?

>>> import collections

>>> a=dict()

>>> a=collections.defaultdict(int)

>>> a[1]

a) 1

b) 0

c) An exception is thrown

d) ' '

2. Which of these is false about recursion?

a) Recursive function can be replaced by a non-recursive function

b) Recursive functions usually take more memory space than non-recursive function

c) Recursive functions run faster than non-recursive function

d) Recursion makes programs easier to understand

3. What will be the output of the following Python code?

def foo(i, x=[]):

x.append(x.append(i))

return x

for i in range(3):

y = foo(i)

print(y)

a) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]

b) [[0], [[0], 1], [[0], [[0], 1], 2]]

c) [0, None, 1, None, 2, None]

d) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]

4. What will be the output of the following Python function?

list(enumerate([2, 3]))

a) Error

b) [(1, 2), (2, 3)]

c) [(0, 2), (1, 3)]

d) [(2, 3)]

5. What is setattr() used for?

a) To access the attribute of the object

b) To set an attribute

c) To check if an attribute exists or not

d) To delete an attribute

6. In which direction is the turtle pointed by default?

a) North

b) South

c) East

d) West

7. What will be the output of the following Python code?

x = [12, 34]

print(len(' '.join(list(map(int, x)))))

a) 4

b) 5

c) 6

d) error

8. What is tail recursion?

a) A recursive function that has two base cases

b) A function where the recursive functions leads to an infinite loop

c) A recursive function where the function doesn't return anything and just prints the values

d) A function where the recursive call is the last thing executed by the function

9. What is unpickling?

a) It is used for object serialization

b) It is used for object deserialization

c) None of the mentioned

d) All of the mentioned

10. 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) Tuple

c) Dictionary

d) An exception is thrown

11. What are the two main types of functions?

a) Custom function

b) Built-in function & User defined function

c) User function

d) System function

12. What will be the output of the following Python code?

class A:

def one(self):

return self.two()

def two(self):

return 'A'

class B(A):

def two(self):

return 'B'

obj1=A()

obj2=B()

print(obj1.two(),obj2.two())

a) A A

b) A B

c) B B

d) An exception is thrown

13. What will be the output of the following Python code?

def printMax(a, b):

if a > b:

print(a, 'is maximum')

elif a == b:

print(a, 'is equal to', b)

else:

print(b, 'is maximum')

printMax(3, 4)

a) 3

b) 4

c) 4 is maximum

d) None of the mentioned

14. What will be the output if we try to extract only the year from the following Python code? (time.struct_time(tm_year=2017, tm_mon=6, tm_mday=25, tm_hour=18, tm_min=26, tm_sec=6, tm_wday=6, tm_yday=176, tm_isdst=0))

import time

t=time.localtime()

print(t)

a) t[1]

b) tm_year

c) t[0]

d) t_year

15. What will be the output of the following Python code?

def fun(n):

if (n > 100):

return n - 5

return fun(fun(n+11));

print(fun(45))

a) 50

b) 100

c) 74

d) Infinite loop

16. What will be the output of the following Python code?

def foo():

try:

return 1

finally:

return 2

k = foo()

print(k)

a) 1

b) 2

c) 3

d) error, there is more than one return statement in a single try-finally block

17. Which of the following statements create a dictionary?

a) d = {}

b) d = {"john":40, "peter":45}

c) d = {40:"john", 45:"peter"}

d) All of the mentioned

18. The special character \B matches the empty string, but only when it is _________

a) at the beginning or end of a word

b) not at the beginning or end of a word

c) at the beginning of the word

d) at the end of the word

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions