September 26

Lists

List is a sequential data type. List values are comma separated and enclose with square bracket.
List in Python is like array in Perl and an array(ArrayList Class) in Java.

Key features of List:

  • List items can be any datatype, within a single list you can have multiple datatype as item
  • List can have duplicate values
  • List is Mutable object
  • Negative index access value from end of the list i.e. tmp_list[n-1] = tmp_list[-1]
  • You can use any integer expression for index

Adding items to list, you can insert item to any place in the list using insert method. append method will insert item at the end.

List has extend and append method,both add values to list but both work differently.
Extend takes single argument,which is always list whereas append can n number of argument and add each item to original list.