0% found this document useful (0 votes)
77 views

Python For Data Science July 2024W2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Python For Data Science July 2024W2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Python for Data Science

Week 2

1. Which of the following oject does not support indexing? [1 mark]

(a) tuple
(b) list
(c) dictionary
(d) set

Answer: d

2. Given a NumPy array, arr = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]), what is the
output of the command, print(arr[0][1])?

(a) [[1 2 3]
[4 5 6]
[7 8 9]]
(b) [1 2 3]
(c) [4 5 6]
(d) [7 8 9]

Answer: c

3. What is the output of the following code?

(a) [2, 3, 4, 5]
(b) [0 1 2 3]

1
(c) [1, 2, 3, 4]
(d) Will throw an error: Set objects are not iterable.

Answer: c

2
4. What is the output of the following code? [1 mark]

(a)

3
(b)

(c)

(d)

Answer: c

4
5. Which of the following code gives output My friend’s house is in Chennai? [1
mark]

(a)

(b)

(c)

(d)

Answer: a, d

6. Let t1 = (1, 2, “tuple”, 4) and t2 = (5, 6, 7). Which of the following will not give any
error after the execution? [1 mark]

(a) t1.append(5)
(b) x = t2[t1[1]]
(c) t3 = t1 + t2
(d) t3 = (t1, t2)
(e) t3 = (list(t1), list(t2))

Answer: (b, c, d, e)

7. Let d = {1 : “Pyhton”, 2 : [1, 2, 3]}. Which among the following will not give the error
after the execution? [1 mark]

(a) d[2].append(4)

5
(b) x = d[0]
(c) d[“one”] = 1
(d) d.update({‘one’ : 2})
Answer: (a, c, d)
8. Which of the following data type is immutable? [1 mark]
(a) list
(b) set
(c) tuple
(d) dictionary
Answer: (c)
9. student = {‘name’: ‘Jane’, ‘age’: 25, ‘courses’: [‘Math’, ‘Statistics’]}
Which among the following will return
{‘name’: ‘Jane’, ‘age’: 26, ‘courses’: [‘Math’, ‘Statistics’], ‘phone’: ‘123-456’}
(a) student.update({‘age’ : 26})
(b) student.update({‘age’ : 26, ‘phone’: ‘123-456’})
(c) student[‘phone’] = ‘123-456’
student.update({‘age’ : 26})
(d) None of the above
Answer: (b, c)
10. What is the output of the following code? [1 mark]

(a) [‘M’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]


(b) [‘m’, ‘a’, ‘h’, ‘e’, ‘s’, ‘h’]
(c) [‘M’, ‘a’, ‘h’, ‘e’, ‘s’, ‘h’]
(d) [‘m’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]
Answer: (a)

You might also like