Explanation:
-
import array as arr
This imports Python's built-in array module and gives it the nickname arr. -
e = arr.array('i', [7, 14, 21, 28])
This creates an array named e with integer type 'i'.
The array contains 4 elements:
e = [7, 14, 21, 28] -
e[:3]
This is slicing the array. It selects the first 3 elements (index 0 to 2):
[7, 14, 21] -
sum(e[:3])
This calculates the sum of the sliced array:
7 + 14 + 21 = 42 -
print(...)
The output will be:
42
Final Output:


0 Comments:
Post a Comment