0% found this document useful (0 votes)
8 views2 pages

List

Uploaded by

rahulvenkat.465
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

List

Uploaded by

rahulvenkat.465
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

LIST

a = []
print(a, type(a))

b = ['Car','Bus','SUV','Train','MPV']
print(b, type(b))

c = [1,2,3,4,5]
print(c)

d = [1,'Car',2.5, complex(1, 4)]


print(d, type(d))

e = [True, True, False]


print(e, type(e))

a = ['A', 'B','C','D','E','F','G','H']
print("length of list: ", len(a))

print(a[:2])
print(a[2:])
print(a[:-2])
print(a[-5:-2])
print(a[:-2:2])
print(a[:-2:3])
print(a[::2])
print(a[::-1])

a = ['A','B','C','D','E']
print(a[::])
print(a[::-1])
print(a)
a.pop(-2)
print(a)
a.pop(-2)
print(a)

line = "This is a line"


print(line)
print(list(line))
b = (list(line) [::-1])
print(b)

import copy
old_list=[[1,2,3],[4,5,6]]
#shallow copy
new_list=copy.copy(old_list)
new_list[0][2]=10
print(old_list)
print(new_list)

Output:
[[1, 2, 10], [4, 5, 6]]
[[1, 2, 10], [4, 5, 6]]

import copy
old_list=[[1,2,3],[4,5,6]]
#deep copy
new_list1=copy.deepcopy(old_list)
new_list1[0][2]=10
print(old_list)
print(new_list1)

Output:
[[1, 2, 3], [4, 5, 6]]
[[1, 2, 10], [4, 5, 6]]

You might also like