Sep. 20, 2012

Built-in List Methods in Python

List Built-In Methods

The data type "List" has several built-in methods.
s = ['h','e','l','l','o']	#create a list
s.append('d')         		#append to end of list
len(s)                		#number of items in list
s.pop(2)              		#delete an item in the middle
s.sort()               		#sorting the list
s.reverse()           		#reversing the list
s.extend(['w','o'])    		#grow list
s.insert(1,2)         		#insert into list
s.remove('d')           	#remove first item in list with value e
s.pop()               		#remove last item in the list
s.pop(1)              		#remove indexed value from list
s.count('o')            	#search list and return number of instances found
s = range(0,10)          	#create a list over range 
s = range(0,10,2)        	#create a list over range with start index and increment

Share this article

Recommended Python Training – DataCamp

For Python training, our top recommendation is DataCamp.

Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.

Datacamp has beginner to advanced Python training that programmers of all levels benefit from.

 

Download Our Free Guide To Learning Python

* indicates required

Read more about:
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, PythonForBeginners.com only recommend products or services that we try personally and believe will add value to our readers.