Why does this python code have a syntax error?

后端 未结 3 542
说谎
说谎 2020-12-12 01:39

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         


        
相关标签:
3条回答
  • 2020-12-12 01:58

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

    0 讨论(0)
  • 2020-12-12 02:10

    In Python 2.7 (and maybe other versions) you can override the print statement with a print function and than override that function.

    To do that you have to add

    from __future__ import print_function
    

    as the first line of your file.

    0 讨论(0)
  • 2020-12-12 02:14

    In Python 2 print is a reserved word and cannot be the name of a variable or method or function.

    0 讨论(0)
提交回复
热议问题