class Node:
def _init_(self, data, next_node = None):
self.data = data
self.next_node = next_node
def _rept_self(self):
return "<Node data: %s>" % self.data
Can someone please explain to me the last line of code?
This is an old method of string formatting in Python, which is inspired by C syntax. The %s is a placeholder which represents a string, and the variable placed after the % will be used in the place of the %s.
A more intuitive syntax for this would be using an fstring, where variables can be written in curly brackets if an f is placed before the start of a string:
return f"<Node data: {self.data}>"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.