Breaking News

Lists in python - tasks and answers

List is a collection in python which is ordered and values inside list can be changed. List can hold all datatypes. To get values from list we can use indexing.
Here are some examples, how we can create a list

Create an empty list
my_list = []
my_list1 = [1,2,3,4,5,6,7,8] # Creates a list of numbers
my_list2 = ["python", "html", "css"] # Creates a list of string
my_list2 = [True, False, True] # Creates a list of boolean
We can also create a list containing values different data types.
my_list = [1, "python", True, 5.6]

List Methods

  1. append
  2. clear
  3. copy
  4. count
  5. extend
  6. index
  7. insert
  8. pop
  9. remove
  10. reverse
  11. sort

No comments