Collections in Python

 

What is List?

·    1) List is Collection in Python, which store the data into sequence.

·     2) List store multiple datatype value like String, Int, Float, Character etc.

·    3) List works on Index value which start from zero (0).

·    4) List is mutable(Changeable at runtime) data structure.

·    5) What can be done?

-        Create List

-        Indexing and Slicing

-        Apply built-in-methods

-        Nested List

Program 1) #Creating a List

           a1=[1,2,3]

           print(“List: ”, a1)

           Output= List: [1,2,3]

 

Program 2) #Duplicate values in List

          a1=[‘Apple’, ‘Mango’]

          print(“Values:”, a1)

          Output= Values: [‘Apple’, ‘Mango’]

 

Program 3) #List Contructor

         a1=list((1,2,3,4,5))

         print(a1)

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

 

Program 4) #List Slicing

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

         print(“Index 1 Value:”, a1[1])

         Output=Index 1 Value: 2

 

Program 5) #List Item Change

         a= [“Apple”, “Mango”, “Kiwi”]

         a[0:1]=[“Orange”, “Cherry”]

         print(a)

         Output= [‘Orange’, ‘Cherry’, ‘Kiwi’]

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!