The list data structure is very flexible It has many unique inbuilt functionalities
Different methods of creating a list, adding, modifying, and deleting elements in the list. Also, learn how to iterate the list and access the elements in the list in detail.
The following are the properties of a list.
Mutable: The elements of the list can be modified. We can add or remove items to the list after it has been created.
Ordered: The items in the lists are ordered.
Heterogeneous: The list can contain different kinds of elements.i.e; they can contain elements of string, integer, boolean, or any type.
Duplicates: The list can contain duplicates i.e., lists can have two items with the same values.
Ex:
mylist=[89,44,55,22,90]
print(mylist)
print(type(mylist))
output:89,44,55,22,90
#Using list() constructor: In general, the constructor of a class has its class name.
mylist=list([34,55,66,77,23])
print(mylist)
ouput:34,55,66,77,23
# list heterogeneous items
mylist = [1.0, 'ram', 30,50,77,'krishna']
print(mylist)
output:1.0, 'ram', 30,50,77,'krishna'
#list functions
#list length function-In order to find the number of items present in a list, we can use the len() function.
mylist = [31, 42, 23,98]
print(len(mylist))
useful post for python learners
ReplyDelete