0

In Java, we make an array of objects with a fixed size as follows

ArrayClass array_of_objects[]=new ArrayClass[10];

but how can I make a list of objects in python with a fixed size?

Malik123
  • 1
  • 1

2 Answers2

2

Create an empty list of size 5

lst = [None] * 5
Orion
  • 158
  • 1
  • 7
2

use numpy like below:

import numpy as np
size = 2
np.array([None]*size, dtype=object)

Output:

array([None, None], dtype=object)

you can use this like below:

arr = np.array([None]*2, dtype=object)
arr[0] = 1
arr[1] = 'str'

Output:

array([1, 'str'], dtype=object)
I'mahdi
  • 23,382
  • 5
  • 22
  • 30