Featured
- Get link
- X
- Other Apps
List in python
One of the most fundamental data structures in any language is the array. Python doesn't have a native array data structures,but it has the list. A list is mutable it means the content of the list are changed
list1= ['tech', 'language', 28, 32,]
List is one of the most used data type in python and us an ordered sequence of elements. All the elements in a list need not be of same data type. List is created by placing all the items inside a square brackets [], separated by commas
Lets see some basic list Operator:
1) length- find length of the list
2) concatenation- concatenate two lists
3) Repetition- repeat the item multiple times
4) Append- add an element to the end of the list
5) Insert- insert an item at the defined index
6) Extend- add all elements of a list to the another list
7) Remove- remove an item from the list
8) Pop- removes an element at the given idex
9) Clear- removes all item from the list
10) Index- return the index of the first match item
Example:
list2=["good"]
print (len(list1))
print(list1+list2)
print(['hi']*4)
list1.append(234)
print(list1)
list1.insert(2,'python')
print(list1)
list1.remove('python')
print(list1)
print(list1.pop())
print(list1)
- Get link
- X
- Other Apps
Comments
Post a Comment