Python

List In Python

Python Collections (Arrays)

If you haven’t check out the last blog Go and read: Declare variable in python

Install Python on windows

There are four types of collection dataype in python.

In this post we will learn about List in python.

List is a collection of multiple data that is ordered and changeable.in python list is written in square brackets.

Let us take an example :

Articles = ["python", "C#", "Angular"]
print(Articles)

Output:

Access List From Index

You can access the list items by the index number:

Articles = ["python", "C#", "Angular"]
print(Articles[0])
#If you want to access the list from reverse order you can use the negative index  
print(Articles[-1])

Output:

 

Range of index

You can give a specific range to you are List , by giving  the starting point end the ending point

When You give range to a list a new list is been created and displayed to us.

Articles = ["python", "C#", "Angular","asp.net","asp.net core"]
print(Articles[2:4])
#By leaving out the start value, the range will start at the first item
print(Articles[:4])
#By leaving out the end value, the range will go on to the end of the list:
print(Articles[1:])
#Specify negative indexes if you want to start the search from the end of the list
print(Articles[-4:-2])

Output:

Change Item Value

You can change the value of list like this:

Articles = ["python", "C#", "Angular","asp.net","asp.net core"]
Articles[1] = 'python 3'
print(Articles)

Output:

 

That’s all about List stay Tune for more Python blogs

 

 

 

 

 

Nisarg Patel

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago