programplug Logo




Python List


Other programming languages use a concept of array.Concept of List in Python work as a data structure,which is used to store various data.
Python list enclosed between square brackets.

list_name=[first,second,third,....n]; 
list1 = ["Ram","Rahul","Mohit"];
list2 = ['A','B','C','D'];
list3 = [1,2,3,4];
list4 = [1234,"Name",'a',2.45];

List example

list1 = ["Rahul","Mohit","Romit"];
print list[2]

output: Romit


Python Concatenation List

Adding or joining two list elements.

list1 = [1,2,3];
list2 = [4,5,6];
list3 = list1+list2
print (list3)

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


Python Replicating Lists

Repeating list element again again using '*'.

list=[1,1]  
print list*2  

output: [1,1,1,1]


Python List Slicing

list =[1,2,3,4,5,7]  
print list[0:2] 

output: [1,4]


Python Updating List

To update or change the value of list.

item=[2,4,8,10]  
print "list are: "  
print item  
item2[2]="New Element"  
print "Values of list are: "  
print item2 

output:
list are:[2,4,8,10]
Values of list are: [2,4,"New Element",10]


Python Deleting Elements

del statement can be used to delete an element from the list.

list=[1,"rahul",2,'a',3]  
print list  
del list[1]  
print list   

output:
[1,2,'a',3]


Python Appending List

append() method is used to add an element at the end of the existing elements.

list=[1,2,"Rohit"]   
list.append(3)  
print "List after appending: "  
print list    

output: List after appending:
[1,2,'a',3]







Our Services

Developing Cheapest Websites
Offer Digital Marketing
Provide College Projects
Attractive Website Developing
Summer Training,Industrial Training
SCO,SMO

Contact Us

Dehradun Uttarakhand India
www.programplug.com
info@programplug.com
08534019974
Designed By : Mridul Gupta

Other Link

About Us

Contact Us

Disclaimer

Privacy Policy