Need help python   " Write an Array Data Structure which has a constructor, "len", "str", "itr", "getitem" and "setitem" methods.   Then create an object of this Array class with 6 elements in it. Fill the object of this class with numbers from 3 to 8.   print the array and show the length of the array object."   Here is the array code """ File: arrays.py An Array is a restricted list whose clients can use only [], len, iter, and str. To instantiate, use = array(, ) The fill value is None by default. """ class Array(object):     """Represents an array."""     def __init__(self, capacity, fillValue = None):         """Capacity is the static size of the array.         fillValue is placed at each position."""         self.items = list()         for count in range(capacity):             self.items.append(fillValue)     def __len__(self):         """-> The capacity of the array."""         return len(self.items)     def __str__(self):         """-> The string representation of the array."""         return str(self.items)     def __iter__(self):         """Supports traversal with a for loop."""         return iter(self.items)     def __getitem__(self, index):         """Subscript operator for access at index."""         return self.items[index]     def __setitem__(self, index, newItem):         """Subscript operator for replacement at index."""         self.items[index] = newItem

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Need help python

 

"

Write an Array Data Structure which has a constructor, "len", "str", "itr", "getitem" and "setitem" methods.

 

Then create an object of this Array class with 6 elements in it. Fill the object of this class with numbers from 3 to 8.

 

print the array and show the length of the array object."

 

Here is the array code

"""
File: arrays.py

An Array is a restricted list whose clients can use
only [], len, iter, and str.

To instantiate, use

<variable> = array(<capacity>, <optional fill value>)

The fill value is None by default.
"""

class Array(object):
    """Represents an array."""

    def __init__(self, capacity, fillValue = None):
        """Capacity is the static size of the array.
        fillValue is placed at each position."""
        self.items = list()
        for count in range(capacity):
            self.items.append(fillValue)

    def __len__(self):
        """-> The capacity of the array."""
        return len(self.items)

    def __str__(self):
        """-> The string representation of the array."""
        return str(self.items)

    def __iter__(self):
        """Supports traversal with a for loop."""
        return iter(self.items)

    def __getitem__(self, index):
        """Subscript operator for access at index."""
        return self.items[index]

    def __setitem__(self, index, newItem):
        """Subscript operator for replacement at index."""
        self.items[index] = newItem

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education