How do i declare an array of class objects in Python 3.4? In C++ i can do it easily such a way:
class Segment
{
public:
long int left, right;
Segment()
{
left = 0;
right = 0;
}
void show_all()
{
std::cout << left << " " << right << endl;
}
};
int main()
{
const int MaxN = 10;
Segment segment[MaxN];
for(int i = 0; i < MaxN; i++)
{
std::cin >> segment[i].left;
std::cin >> segment[i].right;
}
}
In Python i have almost the same but can not find a way to create a list of class' objects and iterate through it as in C++.
class Segment:
def __init__(self):
self.left = 0
self.right = 0
def show_all(self):
print(self.left, self.right)
segment = Segment()
So how to make such a list?