DEV Community

BHARATH KUMAR DAMARLA
BHARATH KUMAR DAMARLA

Posted on

Arrays(Lists) in python

Python does not have a built in array type, but you can use lists for all of the same tasks. An array is a collection of values of the same type saved under the same name.

Each value in the array is called an “element” and indexing that represents its position. You can access specific elements by calling the array name with the desired element’s index. You can also get the length of an array using the len() method.

Alt Text

Unlike programming languages like Java that have static arrays after declaration, Python’s arrays automatically scale up or down when elements are added/subtracted.

For example, we could use the append() method to add an additional element on the end of an existing array instead of declaring a new array.

Arrays(List)

1.cars = ["Toyota", "Tesla", "Hyundai"]
2.print(len(cars))
3.cars.append("Honda")
4.cars.pop(1)
5.for x in cars:
6.  print(x)
Enter fullscreen mode Exit fullscreen mode

Output

3
Toyota
Hyundai
Honda
Enter fullscreen mode Exit fullscreen mode

Top comments (0)