Arrays in Python
Today we will look how to define and use arrays in python.
To understand this, lets have a look at a program.
Using Arrays in Python
user@ngelinux:python$ cat sixth.py
#!/usr/bin/python
mylist = [] ### define array named mylist
mylist.append("first element")
mylist.append("2")
mylist.append("last")
print(mylist[0])
print(mylist[1])
print(mylist[2])
print("")
### Printing all elements of array
for x in mylist:
print(x)
### Print complete array
print(mylist)
Output
We can see in the output, the difference how elements of array got printed, and how a complete array is printed.
user@ngelinux:python$ ./sixth.py first element 2 last first element 2 last ['first element', '2', 'last'] user@ngelinux:python$
