Computer Science, asked by raj20050101, 3 months ago

6.
Predict the output of the following:
>>>a=(0,11,22,33,44,55,66,77,88,99)
>>>print (a[1:7:3])
0​

Answers

Answered by ABKhanDatabase
0

Answer:

[11,44,66]

Explanation:

here is explained

a[start:stop:step]

note: array index starts from 0

step is use for increment of index

a[1:] # prints [11,22,33,44,55,66,77,88,99]

a[:7] #prints [0,11,22,33,44,55,66]

a[1:7] #prints [11, 22,33,44,55,66]

a[1:7:3] #prints [11,44,66]

Answered by dreamrob
0

Given:

a = (0 , 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99)

print(a[1 : 7 : 3])

Output:

(11, 44)

Explanation:

a :             (0 , 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99)

Indexing : 0    1    2     3     4      5     6     7     8     9

a[1 : 7 : 3] : This means we will start from index 1 and move up to index (7 - 1) that is index 6 and will jump 3 steps to get the next element.

So, element at index 1 = 11

Now add 3 to the current index

So, 1 + 3 = 4

Element at index 4 = 44

Now again add 3 to the current index

So, 4 + 3 = 7

We have to move up to index 6. So, 7 is out of range.

Therefore, we will only print (11 , 44)

Similar questions