Q.

Is the following Python code valid?

>>> a=(1,2,3,4)
>>> del a
A.  

No because tuple is immutable

B.  

Yes, first element in the tuple is deleted

C.  

Yes, the entire tuple is deleted

D.  

No, invalid syntax for del method

Similar Questions
1.

Which of the following is a Python tuple?

A.  

[1, 2, 3]

B.  

(1, 2, 3)

C.  

{1, 2, 3}

D.  

{}

2.

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))

3.

What will be the output of the following Python code?

>>>t=(1,2,4,3)
>>>t[1:3]
A.  

(1, 2)

B.  

(1, 2, 4)

C.  

(2, 4)

D.  

(2, 4, 3)

4.

What will be the output of the following Python code?

>>>t=(1,2,4,3)
>>>t[1:-1]
A.  

(1, 2)

B.  

(1, 2, 4)

C.  

(2, 4)

D.  

(2, 4, 3)

5.

What will be the output of the following Python code?

>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
A.  

[2, 3, 9]

B.  

[1, 2, 4, 3, 8, 9]

C.  

[1, 4, 8]

D.  

(1, 4, 8)

6.

What will be the output of the following Python code?

d = {"john":40, "peter":45}
d["john"]
A.  

40

B.  

45

C.  

john

D.  

peter

7.

What will be the output of the following Python code?

>>>t = (1, 2)
>>>2 * t
A.  

(1, 2, 1, 2)

B.  

[1, 2, 1, 2]

C.  

(1, 1, 2, 2)

D.  

[1, 1, 2, 2]

8.

What will be the output of the following Python code?

>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
A.  

True

B.  

False

C.  

Error

D.  

None

9.

What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
A.  

1

B.  

2

C.  

5

D.  

Error

10.

What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
A.  

1

B.  

2

C.  

5

D.  

Error

PYTHON TOPICS