0% found this document useful (0 votes)
6 views

Lecture 3

Love you python

Uploaded by

ffindia6004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture 3

Love you python

Uploaded by

ffindia6004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

List

Week 6: Lecture 3
Adding elements to list using append.
List_new = []
print("Initial blank List: ")
print(List_new)

# Addition of Elements

List_new.append(10)
List_new.append(20)
List_new.append(30)
print("\nList after Addition of Three elements: ")
print(List_new)
Few List Methods
ListA = [2, 4, 2, 6, 7, 2]
print(ListA.count(2)) #counts no. of times element appears
ListA.insert(2,50) #Insert object at specific index
print(ListA)
print(ListA.pop(2)) #Removes an element at the specified index
ListA.remove(2) #removes or deletes and element from the list
print(ListA)
reverse and sort method
ListA = [2, 4, 2, 6, 7, 2]
ListA.reverse() #Reverses the elements in the list
print(ListA)
ListA.sort() #Sorts the elements in the list
print(ListA)
extend method
ListA = [2, 4, 2, 6, 7, 2]
ListB = [100,200,300]
ListA.extend(ListB)
#adds elements in a list to the end of another list
print(ListA)
List_A = [1, 3, 6, 2] + [5, 4, 7] #Concatenation
print (List_A)
print ("Max =", max(List_A)) #prints maximum value
print ("Min =", min(List_A)) #prints minmum value
print ("Sum =", sum(List_A))
#sum operation add the values in the list of numbers
• Thank You

You might also like