<jupyter_start><jupyter_text>Introduction **What?** `__repr__` vs. `__str__` methods  What is the difference? - They both represent the object but the `__repr__` method tells you more. - So much more that you can also reconstruct the object based on that information. - Also Python interpreter sessions use `__repr__` to inspect objects. - `__str__` should have a readable output.  Example 1<jupyter_code>import numpy as np

class Tensor(object):
    
    def __init__(self, data):
        """__init__ method
        Given a list, tunrs it into an array
        """        
        self.data = np.array(data)
    
    def __add__(self, other):
        """__add__ method        
        Add two tensor together
        """
        return Tensor(self.data + other.data)
    
    def __repr__(self):
        print("calling __repr__")
        """__repr__ method
        Returns the object representation in string format.
        Retunrs and official string representation of the object,
        which can be ised to construt the object again.
        """
        return str(self.data.__repr__())
    
    def __str__(self):
        print("calling __str__")
        """
        Returns the string representation of the object. This method is called
        when print() or str() function is invoked on an object. Retunrs a 
        human-redeable string format.
        """
        return str(self.data.__str__())
        
x = Tensor([1,2,3,4,5])
x
repr(x)
str(x)
print(x)<jupyter_output>calling __str__
[1 2 3 4 5]
{'fraction_non_alphanumeric': 0.08802117802779616, 'fraction_numerical': 0.00727994705493051, 'mean_word_length': 2.459954233409611, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '127398', 'license': 'OLDAP-2.3', 'n_tokens_mistral': 444, 'n_tokens_neox': 431, 'n_words': 161, 'path': '__repr__ vs. __str__.ipynb', 'repo_name': 'kyaiooiayk/Python-Programming', 'size': '1511'}