# Python quiz questions

• 1.

What is the output of the following code? Consider Python 2.7.

print tuple[1:3] if tuple == ( 'abcd', 786 , 2.23, 'john', 70.2 ) else tuple()

1. ( 'abcd', 786 , 2.23, 'john', 70.2 )

2. abcd

3. (786, 2.23)

4. None of the above

• 2.

What will be displayed by the following code?

def f(value, values):
v = 1
values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])

1. 1 1

2. 1 44

3. 3 1

4. 3 44

• 3.

What is the output of the following program :

print 'abcefd'.replace('cd', '12')

1. ab1ef2

2. abcefd

3. ab1efd

4. ab12ed2

• 4.

What is the output of the following program :

print 'abef'.partition('cd')

1. (‘abef’)

2. (‘abef’, ‘cd’, ”)

3. (‘abef’, ”, ”)

4. Error

• 5.

What is the output of the following program :

print 'cd'.partition('cd')

1. (‘cd’)

2. (”)

3. (‘cd’, ”, ”)

4. (”, ‘cd’, ”)

• 6.

What is the output of the following program :

i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)

1. 0 1 2 0

2. 0 1 2

3. Error

4. None of the above

• 7.

What is the output of the following program :

i = 0
while i < 3:
print i
i += 1
else:
print 0

1. 0 1 2 3 0

2. 0 1 2 0

3. 0 1 2

4. Error

• 8.

What is the output of the following program :

print '{0:-2%}'.format(1.0 / 3)

1. 0.33

2. 0.33%

3. 33.33%

4. 33%

• 9.

What is the output of the following program :

print '{0:.2}'.format(1.0 / 3)

1. 0.333333

2. 0.33

3. 0.333333:-2

4. Error

• 10.

What is the output of the expression : 3*1**3

1. 27

2. 9

3. 3

4. 1

• 11.

What is the output of the following program :

def myfunc(a):
a = a + 2
a = a * 2
return a

print myfunc(2)

1. 8

2. 16

3. Indentation Error

4. Runtime Error

• 12.

Which of the following statement(s) is TRUE?
A hash function takes a message of arbitrary length and generates a fixed length code.
A hash function takes a message of fixed length and generates a code of variable length.
A hash function may give the same hash value for distinct messages.

1. I only

2. II and III only

3. I and III only

4. II only

• 13.

Which of the following function convert a string to a float in python?

1. int(x [,base])

2. long(x [,base] )

3. float(x)

4. str(x)

• 14.

What data type is the object below ? L = [1, 23, ‘hello’, 1]

1. List

2. Dictionary

3. Tuple

4. Array

• 15.

Which of these is not a core data type?

1. Lists

2. Dictionary

3. Tuples

4. Class

• 16.

Which of the following is correct about Python?

1. It supports automatic garbage collection.

2. It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java

3. Both of the above

4. None of the above

• 17.

To start Python from the command prompt, use the command ______

1. execute python

2. go python

3. python

4. run python

• 18.

____is a simple but incomplete version of a function.

1. Stub

2. Function

3. A function developed using bottom-up approach

4. A function developed using top-down approach

• 19.

Given a string s = “Welcome”, which of the following code is incorrect?

1. print s[0]

2. print s.lower()

3. s[1] = ‘r’

4. print s.strip()

• 20.

What does ~~~~~~5 evaluate to?

1. +5

2. -11

3. +11

4. -5