Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a python array of particular objects

in java, the following code defines an array of the predefined class (myCls):

myCls arr[] = new myCls

how can I do that in python? I want to have an array of type (myCls)?

thanks in advance

like image 951
Moayyad Yaghi Avatar asked Dec 18 '22 04:12

Moayyad Yaghi


1 Answers

Python is dynamically typed. You do not need to (and in fact CAN'T) create a list that only contains a single type:

arr = list()
arr = []

If you require it to only contain a single type then you'll have to create your own list-alike, reimplementing the list methods and __setitem__() yourself.

like image 50
Ignacio Vazquez-Abrams Avatar answered Jan 24 '23 16:01

Ignacio Vazquez-Abrams