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 initself initialdataNone:
self.head None
self.tail None
self.length
if initialdata:
if isinstanceinitialdata, str:
for char in initialdata:
self.appendchar
elif isinstanceinitialdata, Text:
current initialdata.head
while current:
self.appendcurrentchar
current current.next
else:
raise TypeErrorInitial 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
