Lists in Python

Lists

Unlike strings which were immutable, list are mutable, that is we can change

The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.

>>>

>>> squares = [1, 4, 10, 16, 25]

>>> squares

[1, 4, 9, 16, 25]

>>>squares[2]= 9      # this changes the value of 2nd item

>>>square +[36, 49, 64, 81,100]

>>>Squares

1,4,9,16,25,36,49,64,81,100

 

Example-2

>>> letters=[‘a’,’b’,’c’,’d’,’e’,’f’]

>>> letters[2:4]=[‘C’,’D’,’E’]

>>> letter

A,b,C,D,E,f

>>> letter=[‘a’,’b’,’c’,’d’]

>>> Num=[1,2,3,4]

>>>  x=[num][letter]

>>> x

>>> x[0]

[1,2,3,4]

>>> x[0][3]

4

>>> x[1][3]

d

 

 

 

Updated: April 19, 2019 — 11:01 am

Leave a Reply

Your email address will not be published. Required fields are marked *

care4you © 2014 care4you © Revision-1: 2016 care4you © Revision-2: 2019 Connect On Facebook DMCA.com Protection Status
error: Content is protected !!