Question: Python please class String(): def __init__(self, s): self.string = s def __str__(self): return self.string def __repr__(self): return 'String('{}')'.format(self.string) def upper(self): self.string = self.string.upper() def find(self,

Python please

class String(): def __init__(self, s): self.string = s

def __str__(self): return self.string

def __repr__(self): return 'String(\'{}\')'.format(self.string)

def upper(self): self.string = self.string.upper()

def find(self, substring): return self.string.find(substring.string)

def concat(self, other): self.string + other.string return self

def insert(self, index, other): self.string = self.string[:index] + str(other) + self.string[index:]

def reverse(self): s = '' for i in range(len(self.string)-1,-1,-1): s += self.string[i] self.string = s

def equals(self, other): return self.string == other.string

def copy(self): return String(self.string)

# 1. Write __add__ def __add__(self, other): return self # replace this

# 2. Write __radd__ (determines what += does for Strings) def __radd__(self, other): pass

# 3. Write __getitem__ and __setitem__(determines what [ ] does for Strings) def __getitem__(self, i): return String('') # replace this return String(self.string[i])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!