Posts Python List
Post
Cancel

Python List

List

You can declare the list within []

1
>>>a = [1,2,3,4]
  • The List is iterable
    1
    2
    3
    
    >>> a = [1,2,3,4]
    >>> a[0]
        1
    

    Same as string it follows syntax [start:stop:step] Refer : https://techpechu.com/posts/Python-string-slice/

  • You can create a list out of any type
    1
    2
    3
    
    >>> a = "String"
    >>> list(a)
       ['S', 't', 'r', 'i', 'n', 'g']
    
  • The List are mutable means you can modify the value of list post declared
    1
    2
    3
    4
    5
    6
    7
    8
    
    >>> a = "String"
    >>> a = list(a)
    >>> a
      ['S', 't', 'r', 'i', 'n', 'g']
    >>> a[0] = "H"
    >>> a
      ['H', 't', 'r', 'i', 'n', 'g']
      # S is replaced with H on 0th position
    

    List also comes with inbuilt modules have a read on this

Hope you find this useful.


Thanks for reading till end.

Followus on insta @techpechu

Join Our Discord

We do run a youtube channel in Indian regional language Tamil called TechPechu. Do subscribe us for moral support. Happy Learning.

Follow us on instagram @techpechu