#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to do indexing and slicing in python?
Description

To implement the concept of indexing and slicing in python3.

Process

   Every data type in python3 like list,tuple variables stores numbers, strings and characters.

   Every element that starts with index 0.

Positive index:

   Its starts with left to right with positive index number.

Negative index:

   Its starts with right to left with negative index number.

Eg.

Slicing

we can call multiple element in a list

or tuple or any other data type

in pythonby creating a range

of index numbers separated by

a colon [x:y]

Sapmle Code

#simple list and tuple data type
list1=[‘bala’,’naren’,’vivek’,’sathish’,10,45,85,20]
tuple1=(‘bala’,’naren’,’vivek’,’sathish’,10,45,85,20)
list2=[“banana”,”mango”,”jackfruit”]
print(“******Indexing examples******”)

#positive indexing
print(list1[0])

#negative indexing
print(tuple1[-1])
print(“******Slicing examples*******”)

#slicing
print(list1[0:6])
print(tuple1[2:5])

Screenshots