## Python Certification Exam Preparation Set 2

##### hat is the output of the following?print("ab\tcd\tef".expandtabs(4))

Options are :

• ab cd ef
• ab\tcd\tef
• ab cd ef (Correct)
• abcdef

##### The output of executing string.ascii_letters can also be achieved by:

Options are :

• string.ascii_lowercase+string.ascii_upercase (Correct)
• string.ascii_lowercase_string.digits
• string.lowercase_string.upercase
• string.letters

Options are :

• 1
• 4 (Correct)
• 5
• 2
• 7

Options are :

• 0
• error
• 2 (Correct)
• 1

##### What will be the output of the following Python code?matrix = [[1, 2, 3, 4], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]for i in range(0, 4): print(matrix[i][1], end = " ")

Options are :

• 2 5 9 13 (Correct)
• 1 3 8 12
• 4 5 6 7
• 1 2 3 4

##### What will be the output of the following Python code?d = {0: 'a', 1: 'b', 2: 'c'}for x, y in d.items(): print(x, y)

Options are :

• none
• a b c
• 0 1 2
• 0 a 1 b 2 c (Correct)

Answer :0 a 1 b 2 c

##### Suppose list1 is [2445,133,12454,123], what is max(list1)?

Options are :

• 133
• 2445
• 12454 (Correct)
• 123

##### What is the output of the following?print("ab\tcd\tef".expandtabs('+'))

Options are :

• ab++++++++cd++++++++ef
• ab cd ef
• ab+cd+ef
• none (Correct)

##### What will be the output of the following Python code?i = 0while i < 3: print(i) i += 1else: print(0)

Options are :

• 0 1 2 0 (Correct)
• 0 1 2 3 0
• 0 1 2
• error

##### What will be the output of the following Python code snippet?for i in 'abcd'[::-1]: print (i)

Options are :

• a b c d
• error
• d c b a (Correct)
• none

##### What will be the output of the following Python code?for i in range(0): print(i)

Options are :

• none
• error
• 0
• no output (Correct)

Options are :

• A
• Error
• n (Correct)
• Daman

##### What will be the output of the following Python code snippet?x = 2for i in range(x): x -= 2 print (x)

Options are :

• 0 -2 (Correct)
• error
• 0
• 0 1 2 3 4 …

##### What is the output of the following?print("Hello {} and {}".format('foo', 'bin'))

Options are :

• Hello {} and {}
• Error
• Hello
• Hello foo and bin (Correct)

Options are :

• olleh
• o (Correct)
• h
• hello

##### What will be the output of the following Python code?def f(i, values = []): values.append(i) return valuesf(1)f(2)v = f(3)print(v)

Options are :

• [1] [1, 2] [1, 2, 3]
• [1, 2, 3] (Correct)
• [1] [2] [3]
• 1 2 3

##### What will be the output of the following Python code?class Count: def __init__(self, count = 0): self.__count = countc1 = Count(2)c2 = Count(2)print(id(c1) == id(c2), end = " ")s1 = "Good"s2 = "Good"print(id(s1) == id(s2))

Options are :

• True False
• False False
• True True
• False True (Correct)

##### What will be the output of the following Python code?i = 1while True: if i%0O7 == 0: break print(i) i += 1

Options are :

• error
• none
• 1 2 3 4 5 6 (Correct)
• 1 2 3 4 5 6 7

Answer :1 2 3 4 5 6

##### What will be the output of the following Python code?print('{0:.2}'.format(1/3))

Options are :

• 0.333333
• 0.333333:.2
• 0.33 (Correct)
• Error

##### What will be the output of the following Python code?a=[1,2,3,4]b=[sum(a[0:x+1]) for x in range(0,len(a))]print(b)

Options are :

• 10
• 4
• [1,3,6,10] (Correct)
• [1,3,5,7]

##### What will be the output of the following Python code?i = 1while True: if i%2 == 0: break print(i) i += 2

Options are :

• 1
• 1 2 3 4 5 6 …
• 1 3 5 7 9 11 … (Correct)
• 1 2

Answer :1 3 5 7 9 11 …

##### What will be the output of the following Python code?class Name: def __init__(self, firstName, mi, lastName): self.firstName = firstName self.mi = mi self.lastName = lastNamefirstName = "John"name = Name(firstName, 'F', "Smith")firstName = "Peter"name.lastName = "Pan"print(name.firstName, name.lastName)

Options are :

• Peter Pan
• Peter Smith
• John Pan (Correct)
• John Smith

Options are :

• 3
• 5
• 0
• 4 (Correct)

##### What is the output of the following?print("Hello {0} and {1}".format('foo', 'bin'))

Options are :

• Hello 0 and 1
• Hello foo and bin (Correct)
• Error
• Hello {0} and {1} foo bin

Options are :

• a
• d
• c
• b (Correct)

##### What will be the output of the following Python code snippet?print([i+j for i in "abc" for j in "def"])

Options are :

• ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'] (Correct)
• [['da', 'db', 'dc'], ['ea', 'eb', 'ec'], ['fa', 'fb', 'fc']]
• ['da', 'ea', 'fa', 'db', 'eb', 'fb', 'dc', 'ec', 'fc']
• [['ad', 'bd', 'cd'], ['ae', 'be', 'ce'], ['af', 'bf', 'cf']]

##### What will be the output of the following Python code snippet?for i in '': print (i)

Options are :

• None
• nothing is printed (Correct)
• error

##### Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

Options are :

• [0, 1, 2, 3]
• [0.0, 0.5, 1.0, 1.5] (Correct)
• [0, 1, 2, 3, 4]
• [0.0, 0.5, 1.0, 1.5, 2.0]

##### What will be the output of the following Python code snippet?print('abcdefcdghcd'.split('cd'))

Options are :

• ['ab', 'ef', 'gh', "] (Correct)
• ['ab', 'ef', 'gh']
• ('ab', 'ef', 'gh', ")
• ('ab', 'ef', 'gh')

##### What will be the output of the following Python code?i = 5while True: if i%0O9 == 0: break print(i) i += 1

Options are :

• 5 6 7 8
• error (Correct)
• 5 6 7 8 9
• 5 6 7 8 9 10 11 12 13 14 15 ….