Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

The List Data Structure in Python 1

 

In this lecture we will see that,

What is list ?

Which are the different operations of list ?

Which functions are available for list ?

 

The list is most versatile data type available in Python which can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that items in a list need not be of the same type.

 

Example :

list1 = [1,2,3,4,5]

list2 = ["a","b","c","d","e"]

list3 = ['python',34.657,363,64.76,22]

 

Accessing values in list

 

list1 = [1,2,3,4,5,]

 

To print starting value -

print(list1[0])

To print values from start to end -

print(list1[1:5])

 

Updating list

 

list1 = [1,2,3,4,5,]

 

list1[2]=45

print(list1[2])

 

Delete list element

 

list1 = [1,2,3,4,5,]

 

print(list1)

del list1[2]

print (list1)

 

List Operation

 

Python Expression

Results

Description

len([1,2,3])

3

Length

[1,2,3] + [4,5,6]

[1,2,3,4,5,6]

Concatenation

[‘hi’]*4

[‘hi’,’hi’,’hi’,’hi’]

Repetition

3 in [1,2,3]

True

Membership

for x in [1,2,3] :

print x,

1 2 3

Iteration

 

List indexing, slicing, and matrixes

 

L=[1,2,3,4,5,6]

 

Python Expression

Results

Description

L[2]

3

Offsets start at zero

L[-2]

5

Negative: count from the right

L[1:]

[2,3,4,5,6]

Slicing fetches sections

 

List function

 

dir(nameoflist)

help(nameoflist.functionname)

FAQs

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere