Search code examples
pythoncomma-operator

Python Comma between line of code


I want to understand what does the comma do between self.data and self.next = data. Thanks

class Node(object):
  def __init__(self, data, nxt = None):
    self.data, self.next = data, nxt
class Context(object):
  def __init__(self, source, dest):
    self.source, self.dest = source, dest

Solution

  • This

    self.source, self.dest = source, dest
    

    Does this

    self.source = source
    self.dest = dest
    

    It is just a multivariable definition on a single line