Posts

Showing posts with the label List Methods

Python List and its Methods

LIST DATA TYPES: List is a versatile data type exclusive in Python. In a sense it is same as array in C/C++. But interesting thing about list in Python is it can simultaneously hold different type of data. Formally list a ordered sequence of some data written using square brackets([]) and commas(,). #list of having only integers a= [1,2,3,4,5,6] print(a) #list of having only strings b=["hello","john","reese"] print(b) #list of having both integers and strings c= ["hey","you",1,2,3,"go"] print(c) #index are 0 based. this will print a single character print(c[1]) #this will print "you" in list c A subsequence of a sequence is called a slice and the operation that extracts a subsequence is called slicing. Like with indexing, we use square brackets ([ ]) as the slice operator, but instead of one integer value inside we have two, seperated by a colon (:): >>> singe...