Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self, id):
- self.id = id
- self.neighbours = []
- self.distance = 0
- def __str__(self):
- return str(self.id)
- uno = Node(1)
- due = Node(2)
- tri = Node(3)
- qua = Node(4)
- print uno
- 1
- uno.neighbours.append([[due, 4], [tri, 5]])
- print uno.neighbours
- [[[<__main__.Node instance at 0x00000000023A6C48>, 4], [<__main__.Node instance at 0x00000000023A6D08>, 5]]]
- [[2, 4], [3, 5]]
- __repr__ = __str__
- class Pet(object):
- def __init__(self, name, species):
- self.name = name
- self.species = species
- def getName(self):
- return self.name
- def getSpecies(self):
- return self.species
- def Norm(self):
- return "%s is a %s" % (self.name, self.species)
- if __name__=='__main__':
- a = Pet("jax", "human")
- print a
- <__main__.Pet object at 0x029E2F90>
- class Pet(object):
- def __init__(self, name, species):
- self.name = name
- self.species = species
- def getName(self):
- return self.name
- def getSpecies(self):
- return self.species
- def __str__(self):
- return "%s is a %s" % (self.name, self.species)
- if __name__=='__main__':
- a = Pet("jax", "human")
- print a
- jax is a human
- class Node:
- def __init__(self, id, neighbours=[], distance=0):
- self.id = id
- self.neighbours = neighbours
- self.distance = distance
- def __str__(self):
- return str(self.id)
- def __repr__(self):
- return "Node(id={0.id}, neighbours={0.neighbours!r}, distance={0.distance})".format(self)
- # in an elaborate implementation, members that have the default
- # value could be left out, but this would hide some information
- uno = Node(1)
- due = Node(2)
- tri = Node(3)
- qua = Node(4)
- print uno
- print str(uno)
- print repr(uno)
- uno.neighbours.append([[due, 4], [tri, 5]])
- print uno
- print uno.neighbours
- print repr(uno)
- print self._grid.__str__()
- def __str__(self):
- """
- Return a string representation of the grid for debugging.
- """
- grid_str = ""
- for row in range(self._rows):
- grid_str += str( self._grid[row] )
- grid_str += 'n'
- return grid_str
Add Comment
Please, Sign In to add comment