DEV Community

BHARATH KUMAR DAMARLA
BHARATH KUMAR DAMARLA

Posted on

1

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay