10. What is the difference between:
(i) append() and insert()
(ii) remove() and pop
(iv) list and tuple
Answers
1. append() and insert()
- append() adds elements/lists to a given list.
- insert() adds elements at the specified index position mentioned in the syntax.
2. remove() and pop()
- remove() removes the first occurrence of a specified element.
- pop() removes the element from the specified index position and returns the value.
Examples of their usage:
- append()
>>> L = ["Hello", "there", 82, 10, 66, "welcome", 4]
>>> L.append("python")
>>> L
['Hello', 'there', 82, 10, 66, 'welcome', 4, 'python']
- insert()
>>> L = ["Hello", "there", 82, 10, 66, "welcome", 4]
>>> L.insert(2, 56)
>>> L
['Hello', 'there', 56, 82, 10, 66, 'welcome', 4]
- remove()
>>> L = ["Hello", "there", 82, 10, 66, 66, 78 "welcome", 4]
>>> L.remove(66)
>>> L
['Hello', 'there', 56, 82, 10, 66, 78, 'welcome', 4]
- pop()
>>> L = ["Hello", "there", 82, 10, 66, "welcome", 4]
>>> L.pop(3)
10
>>> L
['Hello', 'there', 82, 66, 'welcome', 4]
a = int(input("Enter an integer: "))
b = int(input("Enter a second interger: "))
c = int(input("Enter a third integer: "))
s = a + b + c
print()
print(s, "is the sum of the three integers.")
avg = (a + b + c)//3
print(avg, "is the average of the three integers.")
if s > avg:
d = s - avg
print(d, "is the difference between the sum and the average.")
elif avg > s:
d = avg - s
print(d, "is the difference between the sum and the average.")