Professional Documents
Culture Documents
1) List :
Lists are used to store multiple items in a single variable.
Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and
Dictionary,
all with different qualities and usage.
list are ordered sequence of elements that can hold different
eg.
lst = [2, 4, 7,"Deepak", 3+j6]
When we write list name in python after that we need to click “dot” and tab it will show all the List function.
print(list1)
list2 = [1, 2, 3, 4, 5 ]
list3 = ["a", "b", "c", "d"]
# indexing function
print(list1[0])
list1[0]
print(list1[-3])
my_list = ['one','two','three']
my_list[2]
my_list[1:]
# append() function
Append function will add the item into define list.
my_list.append("four")
my_list
# extend function
In Extend function if we add any string , so it will add all the string sepratly.
my_list.extend("five")
# remove
For remove we use the pop function and by default it will remove the last item
my_list.pop()
my_list.pop(0)
my_list.pop(-1)
my_list
# reverse()
For removing the item from list we use reverse function
my_list.reverse()
# sort()
# by using the sort function we arrange the list in ascending order
my_list.sort()
list2 = [13, 42, 53, 34, 25, 86, 79 ]
list2.sort()
print(list2)
list2.append(100)
list2.extend('121')
print(list2)
print(list2[0:3])
#Pop
# it will remove the last element of the list
aList.pop()
print(aList)
aList
aList.pop(2)
aList
# Insert
By using Insert function we can add the item at a particular index number.
aList = [123, 'xyz', 'zara', 'abc']
aList.insert(3,2010)
print (aList)
aList.insert(2,"Anjali")
print (aList)
#Extend
bList.extend(aList)
aList.append(bList)
aList.extend(bList)
print(aList)
#Reverse
aList.reverse()
print(aList)
#Sort
blist = [8,99,45,33]
blist.sort(reverse = False)
print(blist)
#count
count function is use to show the index no of particular item.
aList = [123, 'xyz', 'zara', 'abc', 123, "zara",1,1,1,1,1,1,1,1,1,1]
aList.count('zara')
print(aList.count(1))
list1.extend(list2)
print(list1.count(2300))