Menu

Objective Type Questions & Answers


Python Programming -Unit-1 Objective Type Questions



1.  Is Python case sensitive when dealing with identifiers?

A . yes

B . no

C . machine dependent

D . none of the mentioned

Answer


2. Following set of commands are executed in shell, what will be the output?  
>>>str="hello"
 >>>str[:2]

A . he

B . lo

C . olleh

D . hello

Answer


3. def example(a):
    a = a + `2`
    a = a*2
    return a
print(example("hello"))

A . indentation Error

B . cannot perform mathematical operation on strings

C . hello2

D . hello2hello2

Answer


4. What is the output of the following?

x = [`ab`, `cd`]
for i in x:
    i.upper()
print(x)

A . [‘ab’, ‘cd’].

B . [‘AB’, ‘CD’].

C . Error

D . [None, None].

Answer


5. What is the output of the following?

i = 2
while True:
    if i%3 == 0:
        break
    print(i)
    i += 2

A . 2 4 6 8 10 …

B . 2 4

C . 2 3

D . Error

Answer


6.  What is the output of the following?

x = `abcd`
for i in range(x):
    print(i)

A . a b c d

B .  0 1 2 3

C . Error

D . none of the mentioned

Answer


7.  What is the output of the following?

d = {0: `a`, 1: `b`, 2: `c`}
for i in d:
    print(i)

A . 0 1 2

B . a b c

C . 0 a 1 b 2 c

D . none of the mentioned

Answer


8. What is the output of the following?

string = "my name is m"
for i in string:
    print (i, end=", ")

A . m, y, , n, a, m, e, , i, s, , m,

B . m, y, , n, a, m, e, , i, s, , m

C . my, name, is, x,

D . Error

Answer


9.  What is the output when following code is executed ? 
>>>print(0xA + 0xB + 0xC) 

A . 0xA0xB0xC

B . Error

C . 0x22

D . 33

Answer


10.  What is the output of the following code ?

>>>print(max("what are you"))

A . Error

B . What

C . y

D . you

Answer


11. What is the output of the following?

print(`abcdefcdghcd`.split(`cd`, -1))

A .  [‘ab’, ‘ef’, ‘gh’].

B .  [‘ab’, ‘ef’, ‘gh’, ”].

C . (‘ab’, ‘ef’, ‘gh’)

D .  (‘ab’, ‘ef’, ‘gh’, ”)

Answer


12. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1) ?

A .  [3, 4, 5, 20, 5, 25, 3].

B .  [1, 3, 3, 4, 5, 5, 20, 25].

C . [3, 5, 20, 5, 25, 1, 3].

D . [4, 5, 20, 5, 25, 1, 3].

Answer


13.  What is the output when following code is executed ?

myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
    if myList[i] > max:
        max = myList[i]
        indexOfMax = i
 
>>>print(indexOfMax)

A . 1

B . 2

C . 3

D . 4

Answer


14. What will be the output?

def f(i, values = []):
    values.append(i)
    return values
 
f(1)
f(2)
v = f(3)
print(v)

A .  [1] [2] [3].

B .  [1] [1, 2] [1, 2, 3].

C . 1 2 3

D . [1, 2, 3].

Answer


15.  What is the output of the following piece of code?

>>> a=(2,3,1,5)
>>> a.sort()
>>> print(a)

A . (1,2,3,5)

B . (5,1,3,2)

C . (5,3,2,1)

D . Error

Answer


16.  Suppose t = (1, 2, 4, 3), which of the following is incorrect?

A . print(t[3])

B . t[3] = 45

C . print(max(t))

D . print(len(t))

Answer


17. Which of these about a set is not true?

A . Mutable data type

B . Allows duplicate values

C . Data type with unordered values

D . Immutable data type

Answer


18. What is the output of the following code?

nums = set([1,1,2,3,3,3,4,4])
print(len(nums))

A . 8

B . Error, invalid syntax for formation of set

C . 4

D . 8

Answer


19. What is the output of the following piece of code?

>>> a={3,4,5}
>>> a.update([1,2,3])
>>> print(a)

A . Error, no method called update for set data type

B . {1, 2, 3, 4, 5}

C . Error, list can’t be added to set

D . Error, duplicate item present in list

Answer


20.  Set makes use of __________ and Dictionary makes use of ____________ ?

A . keys, key values

B . keys, keys

C .  key values, keys

D . key values, key values

Answer


21.  What is the output of the code shown below?

l=[1, 2, 4, 5, 2, `xy`, 4]
print(set(l))
print(l)

A . {1, 2, 4, 5, 2, ‘xy’, 4} [1, 2, 4, 5, 2, ‘xy’, 4]

B . {1, 2, 4, 5, ‘xy’} [1, 2, 4, 5, 2, ‘xy’, 4]

C . {1, 5, ‘xy’} [1, 5, ‘xy’]

D . {1, 2, 4, 5, ‘xy’} [1, 2, 4, 5, ‘xy’]

Answer


22. Suppose d = {“madhu”:521, “naveen”:532}, what happens when we try to retrieve a value using the expression d[“suresh”]?

A . Since “suresh” is not a value in the set, Python raises a KeyError exception

B . It is executed fine and no exception is raised, and it returns None

C . Since “suresh” is not a key in the set, Python raises a KeyError exception

D . Since “susan” is not a key in the set, Python raises a syntax error

Answer


23. Which of these about a dictionary is false?

A . The values of a dictionary can be accessed using keys

B . The keys of a dictionary can be accessed using values

C . Dictionaries aren’t ordered

D . Dictionaries are mutable

Answer


24. What is the output of the following code?

a={1:"A",2:"B",3:"C"}
for i,j in a.items():
    print(i,j,end=" ")

A . 1 A 2 B 3 C

B . 1 2 3

C . 1:”A” 2:”B” 3:”C”

D . A B C

Answer


25. What is the output of the following?

x = (i for i in range(3))
for i in x:
    print(i)
for i in x:
    print(i)

A . 0 1 2

B . error

C .  0 1 2 0 1 2

D .  none of the mentioned

Answer




Relevant Materials :

Python Programming -Unit-1 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-2 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-3 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-4 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-5 Objective Type Questions - [ Python Programming ]


Similar Materials :

R - Programming MCQs - Unit-1 - [ R-Programming ]

R - Programming MCQs - Unit-2 - [ R-Programming ]

R - Programming MCQs - Unit-3 - [ R-Programming ]

R - Programming MCQs - Unit-4 - [ R-Programming ]

R - Programming MCQs - Unit-5 - [ R-Programming ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-1 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-2 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-3 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-4 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-5 - [ FLAT ]

PPS MCQs - Unit-1 - [ PPS ]

PPS MCQs - Unit-2 - [ PPS ]

PPS MCQs - Unit-3 - [ PPS ]

PPS MCQs - Unit-4 - [ PPS ]

PPS MCQs - Unit-5 - [ PPS ]

Object Oriented Programming through Java MCQs - Unit-1 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-2 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-3 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-4 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-5 - [ OOP_JAVA ]

Design and Analysis of Algorithms MCQs - Unit-1 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-2 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-3 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-4 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-5 - [ DAA ]

Software Engineering MCQs - Unit-1 - [ SE ]

Software Engineering MCQs - Unit-2 - [ SE ]

Software Engineering MCQs - Unit-3 - [ SE ]

Software Engineering MCQs - Unit-4 - [ SE ]

Software Engineering MCQs - Unit-5 - [ SE ]

Data Mining MCQs - Unit-1 - [ DM ]

Data Mining MCQs - Unit-2 - [ DM ]

Data Mining MCQs - Unit-3 - [ DM ]

Data Mining MCQs - Unit-4 - [ DM ]

Data Mining MCQs - Unit-5 - [ DM ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-1 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-2 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-3 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-4 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-5 - [ COA ]

Data Structures Objective Type Question Bank-Unit-1 - [ DS ]

Data Structures Objective Type Question Bank-Unit-2 - [ DS ]

Data Structures Objective Type Question Bank-Unit-3 - [ DS ]

Data Structures Objective Type Question Bank-Unit-4 - [ DS ]

Data Structures Objective Type Question Bank-Unit-5 - [ DS ]

Database Management System Objective Type Question Bank-Unit-1 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-2 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-3 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-4 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-5 - [ DBMS ]