Python List

Lists are one of the most powerful tools in Python. They are just like the arrays declared in other languages. But the most powerful thing is that list need not be always homogeneous. A single list can contain strings, integers, as well as objects. Lists can also be used for implementing stacks and queues. Lists are mutable, i.e., they can be altered once declared.

# Declaring and printing list
L = [1, "a" , "string" , 1+2]
print(L)
  
# Adding more items
L.append(6)
print(L)
  
# Removing an item
L.pop()
  
print(L)
  
# Printing a particular item
print(L[1])

The output is :

[1, 'a', 'string', 3]
[1, 'a', 'string', 3, 6]
[1, 'a', 'string', 3]
a

Recent Articles on Python List

Built-in Functions, Programs of List

Built-in Functions

  1. Append(): Add an element to the end of the list
  2. Extend(): Add all elements of a list to the another list
  3. Insert(): Insert an item at the defined index
  4. Remove(): Removes an item from the list
  5. Pop(): Removes and returns an element at the given index
  6. Clear(): Removes all items from the list
  7. Index(): Returns the index of the first matched item
  8. Count(): Returns the count of number of items passed as an argument
  9. Sort(): Sort items in a list in ascending order
  10. Reverse(): Reverse the order of items in the list
  11. Copy(): Returns a shallow copy of the list

Programs of List

More Useful Links



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Recommended Posts:



2 Average Difficulty : 2/5.0
Based on 1 vote(s)






User Actions