Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

String Conversion for Python Containers (Lists, Dicts, …)

This is the final lesson in the course. In it, you’ll see how containers like lists and tuples convert their children to strings when called with str(). The lesson also encourages you to add a .__repr__() method to your classes.

michelnakhla on July 20, 2019

Very brief and nice.

paulakula11 on Aug. 28, 2019

concise and clear

Silver on Dec. 7, 2019

awesome!

Lokman on Feb. 27, 2020

Thanks @DanBader for best practice always provide __repr__ for classes. I guess dunder repr short form for represent.

sroux53 on June 5, 2020

Excellent!

Vaibhav Kumar on July 19, 2020

Very well crisp and concise.

avalidzy on July 23, 2020

Excellent voice delivery! The “dunder” use methodology is more apparent to me. Thanks Dan!

Idris Diba on Aug. 3, 2020

I learned a lot from this tutorial. Thank you Dan for your excellent method of teaching.

vikrant06 on Aug. 16, 2020

neat

Ghani on Oct. 7, 2020

Very good though very short!

cap-gnc on Oct. 9, 2020

Thank you. __str__ vs __repr__ demystified.

geultrin on Nov. 5, 2020

Thanks Dan. Short and sweet. I knew about dunder repr but did not understand it fully. I now see its usefulness

loopology on Nov. 29, 2020

This tutorial is from 2017 and it shows: It’s using “{}”.format() instead of the f”{}” string formatting.

What I miss about all RealPython tutorials: They should state their publication date up front as well as the Python version being used, and possibly what would need to be changed to be up to date.

Abderraouf Z on Nov. 30, 2020

Top explanations!

nathank on Dec. 12, 2020

I thought I knew repr very well but this just adds an additional level of depth. Thanks Dan!

dbristow31 on Jan. 28, 2021

This has been helpful. I made a note to myself to include a repr method to all of my classes, moving forward.

jeffersongarciaor on Jan. 29, 2021

Just amazing to learn new stuffs. Thank you Dan for this tutorial.

shangcode on Feb. 20, 2021

Learned a lot! 😀

Cavalcante on March 18, 2021

That’s Gold! I have seen this use of __ str__ in django when you use the admin interface, but I did not know it worked undercover.

Thanks for the lesson.

amirrastkhadiv on April 7, 2021

That’s informative. Thanks Dan!

Espius Edwards on Sept. 3, 2021

Thank you for your concise tutorial!

François 江戸 D on Sept. 21, 2021

No sooner said than used, my last piece of code got cleaner :)

MakerMike369 on March 7, 2022

Was looking for info for making a “Class template” of sorts. .__repr__() fits the bill nicely!

mckown on June 30, 2022

Excellent presentation! I learned quite a bit. Thanks!

Become a Member to join the conversation.