Python Tutorial | Python List | Add Items in the list | Remove Items in list | Join Items in List

Published: 01 January 1970
on channel: GSS
142
2

In this video, You will learn Python Programming Language.

Python List
"# Add Items in the list:"
"# append() method: add a item to the end of list"
Mylist = [10, "India", -50, 30.22, True ]
Mylist.append("Delhi")
Mylist.append(100)
print(Mylist)

"# insert method: add item to the specific index"
Mylist = [10, "India", -50, 30.22, True]
Mylist.insert(1, "USA")
print(Mylist)

"# Remove Items in list:"
"# remove method: specific item will be removed"
"# If duplicate items are present in the list then" \
"remove method will remove first item in the list"
Mylist = [10, "India", -50, 30.22, True, 10, 10]
Mylist.remove(10)
Mylist.remove(True)
print(Mylist)

"# pop method: remove specific index from list"
Mylist = [10, "India", -50, 30.22, True, 10, 10]
x = Mylist.pop(1)
print(Mylist)
y = Mylist.pop(3)
print(Mylist)

"# In pop method, if you do not specify the index then" \
"it remove the last item from the list"
Mylist = [10, "India", -50, 30.22, True]
Mylist.pop()
print(Mylist)

"# clear method: empty the list"
Mylist = [10, "India", -50, 30.22, True]
Mylist.clear()
print(Mylist)

"# Copy Items in List:"
"# copy method: Will copy list from one to another"
Mylist = [10, "India", -50, 30.22, True]
CopyMylist = Mylist.copy()
print(CopyMylist)

"# list method:"
Mylist = [10, "India", -50, 30.22, True]
CopyMylist = list(Mylist)
print(CopyMylist)

"# Join Items in List:"
"# Using + Operator:"
city = ["Lucknow", "Mumbai", "Bangalore"]
state = ["UP", "Maharastra", "Karnataka"]
address = city + state
print(address)

"# append method:"
city = ["Lucknow", "Mumbai", "Bangalore"]
state = ["UP", "Maharastra", "Karnataka"]
for i in state:
city.append(i)
print(city)

"# extend method"
city = ["Lucknow", "Mumbai", "Bangalore"]
state = ["UP", "Maharastra", "Karnataka"]
city.extend(state)
print(city)

"# sort method: arrange values in ascending order"
Pincode = [10,20,30, 90, 60, 40, 80, 30]
Pincode.sort()
print("Asending:", Pincode)
Pincode.sort( reverse=10)
print("Descending:",Pincode)

"# reverse method"
Pincode = [10,20,30, 90, 60, 40, 80, 30]
Pincode.reverse()
print(Pincode)

"# Python Tuples:"
See the next video...


On this page of the site you can watch the video online Python Tutorial | Python List | Add Items in the list | Remove Items in list | Join Items in List with a duration of hours minute second in good quality, which was uploaded by the user GSS 01 January 1970, share the link with friends and acquaintances, this video has already been watched 142 times on youtube and it was liked by 2 viewers. Enjoy your viewing!