Question: Python How do I get the class Text to call head ( ) in the format of Text.head? I want to be able to type

Python
How do I get the class Text to call head() in the format of Text.head?
I want to be able to type
Text.head
and have it return the first node in the list, to be precise.
class Text:
def __init__(self, initial_data=None):
self.head = None
self.tail = None
self.length =0
if initial_data:
if isinstance(initial_data, str):
for char in initial_data:
self.append(char)
elif isinstance(initial_data, Text):
current = initial_data.head
while current:
self.append(current.char)
current = current.next
else:
raise TypeError("Initial data must be a string or Text object")
def head():
return self.head

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 Programming Questions!