Printing a list of objects of user defined class

前端 未结 3 563
花落未央
花落未央 2020-11-29 06:14

So I have a class, called Vertex.

class Vertex:
    \'\'\'
    This class is the vertex class. It represents a vertex.
    \'\'\'

    def __in         


        
3条回答
  •  迷失自我
    2020-11-29 07:06

    def __ str __ (self):
        return f"Vertex: {self.label} {self.neighbours}"
    
    #In most cases, this is probably the easiest and cleanest way to do it. Not fully sure how this code will interact with your list []. Lastly, any words or commas needed, just add them between the brackets; no further quotes needed.
    

提交回复
热议问题