You are on page 1of 4

#### List #######

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]

All list function:

# how to write List function

When we write list name in python after that we need to click “dot” and tab it will show all the List function.

list1 = ['Python', 'Data Science', 2013, 2018]


list1

print(list1)
list2 = [1, 2, 3, 4, 5 ]
list3 = ["a", "b", "c", "d"]

python_class = ["Basics", "of", "Python"]

# indexing function

list1 = ['of', 'Basics', 2014, 2018]

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

aList = [123, 'xyz', 'tommy', 'abc', 123]


bList = [2009, 'beneli']

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 = ['Python',2018, (6+2j) ,True,23.56]


list2 = [2300,'Hello',False,0.7888,(3j)]

list1.extend(list2)
print(list1.count(2300))

You might also like