Check Item in List :
thislist = ["apple", "banana", "cherry"]
if "apple" in thislist:
print("Yes, 'apple' is in the fruits list")
Output :
Yes, 'apple' is in the fruits list
Replace Item by Index :
thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
print(thislist)
Output :
['apple', 'blackcurrant', 'cherry']
Replace Range of Items :
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"]
thislist[1:3] = ["blackcurrant", "watermelon"]
print(thislist)
Output :
['apple', 'blackcurrant', 'watermelon', 'orange', 'kiwi', 'mango']
Insert Item at Index :
thislist = ["apple", "banana", "cherry"]
thislist.insert(2, "watermelon")
print(thislist)
Output :
['apple', 'banana', 'watermelon', 'cherry']
Append Item :
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
Output :
['apple', 'banana', 'cherry', 'orange']
Extend List with Another List :
thislist = ["apple", "banana", "cherry"]
tropical = ["mango", "pineapple", "papaya"]
thislist.extend(tropical)
print(thislist)
Output :
['apple', 'banana', 'cherry', 'mango', 'pineapple', 'papaya']