Facebook   Tumblr   LinkedIn

Python Lists

Walden Systems Geeks Corner Tutorial Python Lists Rutherford NJ New Jersey NYC New York City North Bergen County
Python is a programming language that lets you work quickly and integrate systems more effectively.

Lists are similar to arrays declared in other languages. Lists doesn't need be homogeneous which makes it a powerful tool in Python. A single list may contain dataTypes like integers, strings, as well as objects. Lists are also very useful for implementing stacks and queues. Lists are mutable which means that they can be changed. In Python, list is a type of container which is used to store multiple data at the same time. Unlike sets, the list in Python are ordered and have a definite count. The elements in a list are indexed according to a defined sequence and the indexing of a list is done with 0 being the first index. Each element in the list has its place in the list, which allows duplicating of elements in the list, with each element having its own distinct place and credibility.

Lists in Python can be created by just placing the sequence inside the square brackets. Unlike sets, list doesn't need a built-in function for creation of list. A list may contain duplicate values with their distinct positions. Elements can be added to the list by using the built-in append() function. Only one element can be added at a time to the list by using append() method. To add multiple elements with the append() method, loops are used. Tuples can also be added to the list with the use of append method because tuples are immutable. Unlike sets, lists can also be added to the existing list with the use of append() method. The append() method only works for adding elements at the end of the list, To add elements at a desired position, insert() method is used. Unlike append() which takes only one argument, insert() method requires two arguments, position and value. Other than append() and insert() methods, there's one more method for adding elements, extend(), this method adds multiple elements at the same time at the end of the list.

In order to access the list items refer to the index number. Use the index[] operator to access an item in a list. The index must be an integer. Elements can be removed from the list by using built-in remove() function but you will get an error if the element doesn't exist in the set. The Remove() method only removes one element at a time, to remove range of elements, iterator is used. The Pop() function can also be used to remove and return an element from the set, but by default it removes only the last element of the set, to remove element from a specific position of the list, index of the element is passed as an argument to the pop() method.

List is a power tool in Python to hold multiple values in a single variable. Lists allows us to hold multiple values inside a single variable. We can access and modify individual elements in the list. We can grow and shrink the list as we need.