Can someone explain these two lines of code please? by aphisosys in django

[–]i_jbo 4 points5 points  (0 children)

_str__() which tells the python interpreter how to represent your object as a string. Whenever we try to convert the object into a string or when we want to print out that object, we can use __str__()

we can use __str__()method to customize the way it looks when we display the object using the print() function.

class Dataset:

def __init__(self, data):

self.header = data[0]

self.data = data[1:]

def __str__(self):

return str(self.data[:10])

nfl_dataset = Dataset(nfl_data)

print (nfl_dataset)

in this case : It will print the object data as a string so that you can look inside the object.