A Python list is a sequence data type similar to array. It contains characters(numbers, letters, words) separated by commas and enclosed in square brackets ([]). A list can consist of all elements as numbers, characters or a combination of both. The arrangement of the elements in a list is not specified (it can be sorted or unsorted). There is a concept of order in lists. Every element has a particular index. The element can be called or deleted or replaced by another number using the index of that element.

Python List – Built-in Functions

There are some built-in functions used to perform various operations on lists.

1. append(x) – append() is used to add item x at the end of the list. If you add an element to the list using (+) sign, then the element will get added to the list for the particular statement. But, if you add the element using append(), then the element will get permanently added to the list.

2. extend(L) – This built-in function is used to add all items in given list L to the end. It permanently adds up the elements of one list to another list.

3. insert(i , x) – This built-in function is used to insert item x at position i in the list.

4. remove(x) – This built-in function is used to remove the item that is equal to x from the list.

5. clear() – This built-in function is used to remove all items and empty the list.

6. index(x) – This built-in function is used to return the index of item x. It will return the index of the first occurrence of x if item x occurs more than once in the given list.

7. count(x) – This built-in function is used to return a number of items that is equal to x. Basically, it will count the number of times x occurs in the list and will return that count.

8. sort() – This built-in function is used to sort items in a list in ascending order.

9. reverse() –This built-in function is used to reverse the order of items in the list.

10. copy() – This built-in function is used to return a shallow copy of the list.

a) You can print out a particular element just by specifying its index. Remember index starts from zero.
b) You can print out a specific part of the list by slicing the list. Specify start index, end index and the number of steps.
c) You can print the list to a particular index.
d) You can get the number of elements of the list by len() function.
e) You can reverse a whole string by using [::-1]. Here, -1 refers to the direction of the list.

Good day my good friend! I must express that this informative article is definitely incredible, pleasant written and can include most considerable infos. I want to notice far more content such as this professional hosting.