Informatics Practices

Consider two objects x and y. x is a list whereas y is a Series. Both have values 20, 40, 90, 110.

What will be the output of the following two statements considering that the above objects have been created already ?

(a) print (x*2)

(b) print (y*2)

Justify your answer.

Python Pandas

5 Likes

Answer

(a)

Output
[20, 40, 90, 110, 20, 40, 90, 110]

In the first statement, x represents a list. When a list is multiplied by 2 (x*2), it replicates each element of the list twice.

(b)

Output
0     40
1     80
2    180
3    220
dtype: int64

In the second statement, y represents a Series. When a Series is multiplied by a value, each element of the Series is multiplied by 2, as Series supports vectorized operations.

Answered By

2 Likes


Related Questions