In this video, I have explained about data type. Python List is one of the most widely used data type used to store multiple values. It is used in most of the applications. Slicing of Python Lists is explained in detail. How to add, remove, and many other functions are used to make it more clear. To know more watch the complete video.

DATATYPE – PYTHON LISTS AND SLICING

Python lists are the most versatile and useful datatype. Lists can store a sequence of data within it, which are separated by comma and enclosed inside square brackets. The good feature of Python Lists is, the data or items stored can be of mixed data types like strings, integer, float, etc. can be stored into a single sequence.

Example:

List1 = [“A”, 21, 78, “Red”, 50, “Apple”]

In this way a list is created, items inside the list are separated by a comma and string is always stored into double quote as explained earlier.

Usually when there are multiple data stored inside an array, list, tuple, etc. the indexing of it starts from zero. For example List1[0] = ‘A’ and it ends on n-1. There are many other ways of accessing items inside a list as explained in my video. You can perform addition of two or more lists. Let see some more about Lists in detail.

Some functions to be used with Lists are:

  • ListName.append(): This function is used to add the value into the List.
  • del ListName[index number]: This  function will delete a particular item which is mapped using the index number.( For example, del List1[2]; This will delete the integer 78 from the existing list).
  • len (ListName): This function will give the total number of items present inside your List.
  • max(ListName): This function gives the maximum value inside the List. When the list is of only integers, it gives maximum or largest integer present. When the list is of only strings, it gives the longest string which has the most numbers of characters. It does not work when the List are having items of mixed data types.
  • mix(ListName): This function gives the minimum value inside the List. Same concept applies here for integer, string and mixed data types as in max().
  • ListName.count(any item): This function is used to count the repetition of particular item in your list.
  • sorted(ListName): This function is used to sort the List. If the items are alphabet or string, sorting will be done in alphabetical order. If the items are numeric, sorting will be done in ascending order.
  • sum(ListName): This function is used to sum all the items or elements in your List. This is used for numeric values.

So in this way you can create a Python List, access it, append new values, remove the existing values, count the number of repetition of particular items, get the length or total count of items inside a list, get the minimum and maximum value in your list.