Python List

A Python list is a general and widely used document that represents a collection of objects in a particular order. Lists are subject to change; that is, they can be modified after creation and  can contain  different data elements, including integers, floating point numbers, strings, and aliases. A list is defined by enclosing the items in square brackets [] and separating them with commas.   
Here is an example of a simple Python list:  
my_list = [1, 2, 3, 4, 5]    
In this example, my_list is a Python list containing five numbers.   Names in Python have many properties and properties:   
1. Ordered collection: A document that maintains the order of content as it is placed, allowing  indexed access and retrieval.   
2. Variable: After the form is created, changes can be made. You can add, delete or change content to the list. 
3. Heterogeneous elements: Notifications can contain heterogeneous data elements that allow changes in data representation.   4. Dynamic resizing: The size of the document will dynamically increase or decrease as content is added or removed.   5. Index access: You can use zero-based index to see the contents of the document. You can access individual contents by specifying their position in the list.   
6. Iterable: Lists can be iterated; This means you can iterate over each element using a loop or input.   

The following is an example showing some  operations of Python lists:   
# Define a list  
mylist = [1, 2, 3, 4, 5]   

# Contents  
print (mylist[2]) # Output: 3   

# Replace items  
mylist[1] = 10  
print(my_list)  # Output [1, 10, 3, 4, 5]
my_list .append(6)  
print(my_list) # Output: [1, 10, 3, 4, 5, 6]   

# delete item  
my_list.remove(3) # output [1 , 10 , 4, 5, 6]  

# iterate over   items 
for num in my_list:
  print  (num)

Stephen Olubanji Akinpelu

Previous Post Next Post