Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:53:42+00:00 2026-06-17T22:53:42+00:00

To practice python, I made a simple class for a tree structure in which

  • 0

To practice python, I made a simple class for a tree structure in which each node can have infinite child nodes.

class Tree():

  def __init__(self, children, val):
    self.children = children
    self.val = val

  def add(self, child):
    self.children.append(child)

  def remove(self, index):
    child = self.children[index]
    self.children.remove(child)
    return child

  def print(self):
    self.__print__(0)

  def __print__(self, indentation):
    valstr = ''
    for i in range(0, indentation):
      valstr += ' '
    valstr += self.val
    for child in self.children:
      child.__print__(indentation + 1)

However, I have a syntax error in the line def print(self):. Where is the error? I have been looking for a long time, and it seems like the right way to define a python function.

I have also tried

  @override
  def print(self):
    self.__print__(0)

to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:53:43+00:00Added an answer on June 17, 2026 at 10:53 pm

    In Python 2 print is a keyword, so you can’t use it as the name of a function or method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently made a very simple practice program in Python, that takes user input
I have a simple python application where my directory structure is as follows: project/
I have a python IRC bot that I'm starting to work on to practice
I have client-server architecture build in python, unfortunately the original design was made that
I have a Python project with the following directory structure: project/ project/src/ project/src/somecode.py project/src/mypackage/mymodule.py
I have write a python library app(which contains several *.py files). And several of
I made a very simple kernel below to practice CUDA. import pycuda.driver as cuda
I need help understanding a practice exam problem for a CS class in python.
I recently learned Python (2.7) and have been making some simple board games with
What is the standard practice in Python when I have a command-line application taking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.