Use of this " __str__ " method

Mam a wala str method ka thora use example deke samja dijiye na…
@dsedyoda

1 Like

@sayanalu9091

The str function in Python is simply used to return the output of the Python functions in a string format .

This function is mainly used with the user-defined functions since their outputs are generally not in the string format.

image

1 Like

And mam ye __repr__ka kya kam

@dsedyoda

@sayanalu9091

The repr() method returns a more detailed string representation of an object.

This method is called by the built-in repr() function. If possible, the string returned should be a valid Python expression that can be used to recreate the object.

repr() is mainly used for debugging and development.

Can you explain these two functions with examples so that we can understand better

@shams55663377

Examples and details are given above.