Computer Science, asked by amriteshrami, 1 month ago

Programming Question. PLs tell fast

Attachments:

Answers

Answered by anindyaadhikari13
9

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

A list named L is created.

> L = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

To display 20, 30, 40, 50 from the list, write the statement given below:

> print(L[1 : 5])

Explanation: The required numbers in the list are present in the range (1, 4). They are accessed using list slicing. As last value is excluded, we will write 5 instead of 4.

To display last 5 elements, write the statement given below:

> print(L[-5 : ])

Explanation: Python supports negative indexing. Index of the fifth element of the list from the last is -5. To access them, we wrote L[-5 : ].

Output of print(L[-5 : -1]) is:

> [60, 70, 80, 90]

Explanation: Here, we are accessing last 5 elements. The last element is excluded. So, the output is [60, 70, 80, 90].

\textsf{\large{\underline{Learn More}:}}

List: A list is one of the most widely used data types in Python. It can store multiple items of different types inside a single variable.

Declaration: list_name = ()  or, list_name = [ ]

Initialization: list_name = [element1, element2, . . .]

Characteristics:

  1. Ordered.
  2. Changeable or mutable.
  3. Allow duplicates.
  4. Dynamic.
  5. Can be nested.
Similar questions