You are on page 1of 2

//int / float / string / boolean

//complex datatypes:- List, Tuple, Set, Dictionary

// List =>

- List is an ordered(sequenced) collection of elements enclosed within [ ]


- Lists are mutable (data can be modified)

eg :- l1 = [1, 'a', true, 4.5, 'hello'] // size =5


l2 = ["Apple", "Grapes", "melon"]

first index = l1[0] # 1


last index = l1[-1] # 'hello'

=> Extracting individual Elements from a list


l1[1] // 'a'
- sequence of element
l1[1:4] // ['a', true, 4.5]

=> Modifying a list


- changing the element at 3rd index
l1[3] = 100
// [1, 'a', true, 100, 'hello']
- Appending a new element (adding) at last
l1.append('Tcil')
// [1, 'a', true, 100, 'hello', 'Tcil']
- popping the last element
myvalue=l1.pop() // it will pop out the last element
[1, 'a', true, 100, 'hello']
=> Modifying a list
- Reversing element of list
l1 = [1, 'a', 2, 'b', 3, 'c']
l1.reverse()
['c', 3, 'b', 2, 'a', 1]
inserting element at a specified index
l1.insert(1, 'testing')
[1, 'testing', 'a', 2, 'b', 3, 'c']
sorting a list
l1= ["grapes", "apple", "mango", "banana"]
l1.sort()
[ "apple", "banana", "grapes", "mango"]

ASCII
A-Z(65-90)
a-z (97-122)
0-9(48-57)

You might also like