DEV Community

Cover image for Lists/array
Abu zubaer
Abu zubaer

Posted on

Lists/array

I am going to writing about the most used data structure list/array's. if you don't know what is a data structure, don't worry, I will explain.

we know that on the computer we just play with data. we can not think without data. we can not do anything without data.
watching movie? these are data. text is a data, image is data even number or string are also a data.

Alt Text

The programmer's duty is to solve the problem by using data. to easily solve the problem programmers need to structure their data in many ways.
list/array one of them.

previously we had known, how to assign data in a variable.
in python language we assign data

Alt Text
like this.
suppose we have a country variable and have to assign all the city's names under the country. what we're gonna do.

in this situation, we have to use the list/array's structure.

example:
country = ['city1','city2','city3'] --> this is list's.
Alt Text

you can see in the picture the index starts at 0.
remember this in the list count from zero 0.
if you want to print city1 from the country list. you should define index number 0.

print(country[0])

the result will print city1.

there have some methods on the list.
these are --> append,pop,reverse,sort etc.
if you want to add another city to the country list you can do this by using the append method.
example:
country.append('city4')
print(country)

city4 will be added to the last of the country list.

if you want to delete the last index of the country you can do this by using the pop() method.
example:
country.pop()
print(country)

in python language, there have many list methods. and these are easy to use. that's why I don't explain all.
go google and search to write list method in python. you will get lots of resources.

whatever, don't forget to do googling...

this is for today.
thanks for reading.

Top comments (0)