Computer Science, asked by sriyalaxmidora, 20 days ago

Consider a series s1 = [1,4,6,8,10,12,14] , Which statement will produce output as [4,6,8,10]

Answers

Answered by anindyaadhikari13
3

\texttt{\textsf{\large{\underline{Correct Question}:}}}

  • Consider a list s1 = [1,4,6,8,10,12,14] , Which statement will produce output as [4,6,8,10].

\texttt{\textsf{\large{\underline{Solution}:}}}

Given list:

> s1 = [1, 4, 6, 8, 10, 12, 14]

Now, let us see the index of each elements in the list.

 \boxed{\begin{array}{c|c}\tt  \underline{Element}:&\tt \underline {Index}:\\ \tt1&\tt0\\ \tt4&\tt1\\ \tt6&\tt2\\ \tt8&\tt3\\ \tt10&\tt4\\ \tt12&\tt5\\ \tt14&\tt6\end{array}}

We have to display elements from index 1 to 4 using slicing. The códe goes like –

> s1[1 : 5]

Output:

> [4, 6, 8, 10]

Note: As last value is excluded, I have written 5 in place of 4.

Similar questions