Important Notice:

Course Content
List Manipulation in Python (Chapter-7) M3-R5
About Lesson
2. By using slice operator:-

Syntax:- [start:stop:step]

Start:- यह starting index को indicate करता है जिसकी by default value (0) होती है।

Stop:- यह list में last index को indicate करता है जिसकी by default value list में maximum length से एक कम होती है।

Step:- यह एक increment value होती है इसकी by default value 1 होती है।

List1

10

20

‘Anil’

40

‘Ram’

60

Postive index

0

1

2

3

4

5

Negative index

-6

-5

-4

-3

-2

-1

print(list1[0:6])                         # [10, 20, ‘anil’, 40, ‘ram’, 60]

print(list1[2:4])                          # [‘anil’, 40]

print(list1[:5:])                           # [10, 20, ‘anil’, 40, ‘ram’]

print(list1[2::])                           # [‘anil’, 40, ‘ram’, 60]

print(list1[-1:-4:-1])                   # [60, ‘ram’, 40]

 
2. By using slice operator:-

Syntax:- [start:stop:step]

Start:- This indicates the starting index which has a default value of (0).

Stop:- It indicates the last index in the list whose by default value is one less than the maximum length in the list.

Step:- This is an increment value, its default value is

List1

10

20

‘Anil’

40

‘Ram’

60

Postive index

0

1

2

3

4

5

Negative index

-6

-5

-4

-3

-2

-1

print(list1[0:6])                            # [10, 20, ‘anil’, 40, ‘ram’, 60]

print(list1[2:4])                            # [‘anil’, 40]

print(list1[:5:])                            # [10, 20, ‘anil’, 40, ‘ram’]

print(list1[2::])                           # [‘anil’, 40, ‘ram’, 60]

print(list1[-1:-4:-1])                   # [60, ‘ram’, 40]

error: Content is protected !!