class_docstr: A Tree represents a hierarchical grouping of leaves and subtrees.
  For example, each constituent in a syntax tree is represented by a single Tree.
  
  A tree's children are encoded as a list of leaves and subtrees,
  where a leaf is a basic (non-tree) value; and a subtree is a
  nested Tree.
  
      >>> from nltk.tree import Tree
      >>> print(Tree(1, [2, Tree(3, [4]), 5]))
      (1 2 (3 4) 5)
      >>> vp = Tree('VP', [Tree('V', ['saw']),
      ...                  Tree('NP', ['him'])])
      >>> s = Tree('S', [Tree('NP', ['I']), vp])
      >>> print(s)
      (S (NP I) (VP (V saw) (NP him)))
      >>> print(s[1])
      (VP (V saw) (NP him))
      >>> print(s[1,1])
      (NP him)
      >>> t = Tree.fromstring("(S (NP I) (VP (V saw) (NP him)))")
      >>> s == t
      True
      >>> t[1][1].set_label('X')
      >>> t[1][1].label()
      'X'
      >>> print(t)
      (S (NP I) (VP (V saw) (X him)))
      >>> t[0], t[1,1] = t[1,1], t[0]
      >>> print(t)
      (S (X him) (VP (V saw) (NP I)))
  
  The length of a tree is the number of children it has.
  
      >>> len(t)
      2
  
  The set_label() and label() methods allow individual constituents
  to be labeled.  For example, syntax trees use this label to specify
  phrase tags, such as "NP" and "VP".
  
  Several Tree methods use "tree positions" to specify
  children or descendants of a tree.  Tree positions are defined as
  follows:
  
    - The tree position *i* specifies a Tree's *i*\ th child.
    - The tree position ``()`` specifies the Tree itself.
    - If *p* is the tree position of descendant *d*, then
      *p+i* specifies the *i*\ th child of *d*.
  
  I.e., every tree position is either a single index *i*,
  specifying ``tree[i]``; or a sequence *i1, i2, ..., iN*,
  specifying ``tree[i1][i2]...[iN]``.
  
  Construct a new tree.  This constructor can be called in one
  of two ways:
  
  - ``Tree(label, children)`` constructs a new tree with the
      specified label and list of children.
  
  - ``Tree.fromstring(s)`` constructs a new tree by parsing the string ``s``.
class_docstr_tok: ["A","Tree","represents","a","hierarchical","grouping","of","leaves","and","subtrees",".","For","example",",","each","constituent","in","a","syntax","tree","is","represented","by","a","single","Tree",".","A","tree","'s","children","are","encoded","as","a","list","of","leaves","and","subtrees",",","where","a","leaf","is","a","basic","(","non-tree",")","value",";","and","a","subtree","is","a","nested","Tree",".",">",">",">","from","nltk.tree","import","Tree",">",">",">","print","(","Tree","(","1",",","[","2",",","Tree","(","3",",","[","4","]",")",",","5","]",")",")","(","1","2","(","3","4",")","5",")",">",">",">","vp","=","Tree","(","'VP","'",",","[","Tree","(","'","V","'",",","[","'saw","'","]",")",",","...","Tree","(","'NP","'",",","[","'him","'","]",")","]",")",">",">",">","s","=","Tree","(","'S","'",",","[","Tree","(","'NP","'",",","[","'","I","'","]",")",",","vp","]",")",">",">",">","print","(","s",")","(","S","(","NP","I",")","(","VP","(","V","saw",")","(","NP","him",")",")",")",">",">",">","print","(","s","[","1","]",")","(","VP","(","V","saw",")","(","NP","him",")",")",">",">",">","print","(","s","[","1,1","]",")","(","NP","him",")",">",">",">","t","=","Tree.fromstring","(","``","(","S","(","NP","I",")","(","VP","(","V","saw",")","(","NP","him",")",")",")","''",")",">",">",">","s","==","t","True",">",">",">","t","[","1","]","[","1","]",".set_label","(","'","X","'",")",">",">",">","t","[","1","]","[","1","]",".label","(",")","'","X'",">",">",">","print","(","t",")","(","S","(","NP","I",")","(","VP","(","V","saw",")","(","X","him",")",")",")",">",">",">","t","[","0","]",",","t","[","1,1","]","=","t","[","1,1","]",",","t","[","0","]",">",">",">","print","(","t",")","(","S","(","X","him",")","(","VP","(","V","saw",")","(","NP","I",")",")",")","The","length","of","a","tree","is","the","number","of","children","it","has",".",">",">",">","len","(","t",")","2","The","set_label","(",")","and","label","(",")","methods","allow","individual","constituents","to","be","labeled",".","For","example",",","syntax","trees","use","this","label","to","specify","phrase","tags",",","such","as","``","NP","''","and","``","VP","''",".","Several","Tree","methods","use","``","tree","positions","''","to","specify","children","or","descendants","of","a","tree",".","Tree","positions","are","defined","as","follows",":","-","The","tree","position","*","i","*","specifies","a","Tree","'s","*","i","*","\\","th","child",".","-","The","tree","position","``","(",")","``","specifies","the","Tree","itself",".","-","If","*","p","*","is","the","tree","position","of","descendant","*","d","*",",","then","*","p+i","*","specifies","the","*","i","*","\\","th","child","of","*","d","*",".","I.e.",",","every","tree","position","is","either","a","single","index","*","i","*",",","specifying","``","tree","[","i","]","``",";","or","a","sequence","*","i1",",","i2",",","...",",","iN","*",",","specifying","``","tree","[","i1","]","[","i2","]","...","[","iN","]","``",".","Construct","a","new","tree",".","This","constructor","can","be","called","in","one","of","two","ways",":","-","``","Tree","(","label",",","children",")","``","constructs","a","new","tree","with","the","specified","label","and","list","of","children",".","-","``","Tree.fromstring","(","s",")","``","constructs","a","new","tree","by","parsing","the","string","``","s","``","."]
docstr: :return: A pretty-printed string representation of this tree.
  :rtype: str
  :param margin: The right margin at which to do line-wrapping.
  :type margin: int
  :param indent: The indentation level at which printing
      begins.  This number is used to decide how far to indent
      subsequent lines.
  :type indent: int
  :param nodesep: A string that is used to separate the node
      from the children.  E.g., the default value ``':'`` gives
      trees like ``(S: (NP: I) (VP: (V: saw) (NP: it)))``.
docstr_tok: [":","return",":","A","pretty-printed","string","representation","of","this","tree",".",":","rtype",":","str",":","param","margin",":","The","right","margin","at","which","to","do","line-wrapping",".",":","type","margin",":","int",":","param","indent",":","The","indentation","level","at","which","printing","begins",".","This","number","is","used","to","decide","how","far","to","indent","subsequent","lines",".",":","type","indent",":","int",":","param","nodesep",":","A","string","that","is","used","to","separate","the","node","from","the","children",".","E.g.",",","the","default","value","``","'",":","'","``","gives","trees","like","``","(","S",":","(","NP",":","I",")","(","VP",":","(","V",":","saw",")","(","NP",":","it",")",")",")","``","."]
code: def pformat(
      self, margin=70, indent=0, nodesep="", parens="()", quotes=False
  ):
      """
      :return: A pretty-printed string representation of this tree.
      :rtype: str
      :param margin: The right margin at which to do line-wrapping.
      :type margin: int
      :param indent: The indentation level at which printing
          begins.  This number is used to decide how far to indent
          subsequent lines.
      :type indent: int
      :param nodesep: A string that is used to separate the node
          from the children.  E.g., the default value ``':'`` gives
          trees like ``(S: (NP: I) (VP: (V: saw) (NP: it)))``.
      """
  
      # Try writing it on one line.
      s = self._pformat_flat(nodesep, parens, quotes)
      if len(s) + indent < margin:
          return s
  
      # If it doesn't fit on one line, then write it on multi-lines.
      if isinstance(self._label, str):
          s = f"{parens[0]}{self._label}{nodesep}"
      else:
          s = f"{parens[0]}{repr(self._label)}{nodesep}"
      for child in self:
          if isinstance(child, Tree):
              s += (
                  "\n"
                  + " " * (indent + 2)
                  + child.pformat(
                      margin, indent + 2, nodesep, parens, quotes
                  )
              )
          elif isinstance(child, tuple):
              s += "\n" + " " * (indent + 2) + "/".join(child)
          elif isinstance(child, str) and not quotes:
              s += "\n" + " " * (indent + 2) + "%s" % child
          else:
              s += "\n" + " " * (indent + 2) + repr(child)
      return s + parens[1]
  
imports: import re
  from nltk.grammar import Nonterminal, Production
  from nltk.internals import deprecated
label_desc: Use image node_id 42 for calling the Tree obj's underlying member method code with example usage: obj.pformat(margin, indent, nodesep, parens, quotes) and returns: unknown, s