Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

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.

Avatar image for michelnakhla

michelnakhla on July 20, 2019

Very brief and nice.

Avatar image for paulakula11

paulakula11 on Aug. 28, 2019

concise and clear

Avatar image for Silver

Silver on Dec. 7, 2019

awesome!

Avatar image for Lokman

Lokman on Feb. 27, 2020

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

Avatar image for sroux53

sroux53 on June 5, 2020

Excellent!

Avatar image for Vaibhav Kumar

Vaibhav Kumar on July 19, 2020

Very well crisp and concise.

Avatar image for avalidzy

avalidzy on July 23, 2020

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

Avatar image for Idris Diba

Idris Diba on Aug. 3, 2020

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

Avatar image for vikrant06

vikrant06 on Aug. 16, 2020

neat

Avatar image for Ghani

Ghani on Oct. 7, 2020

Very good though very short!

Avatar image for cap-gnc

cap-gnc on Oct. 9, 2020

Thank you. __str__ vs __repr__ demystified.

Avatar image for geultrin

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

Avatar image for loopology

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.

Avatar image for Abderraouf Z

Abderraouf Z on Nov. 30, 2020

Top explanations!

Avatar image for nathank

nathank on Dec. 12, 2020

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

Avatar image for dbristow31

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.

Avatar image for jeffersongarciaor

jeffersongarciaor on Jan. 29, 2021

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

Avatar image for shangcode

shangcode on Feb. 20, 2021

Learned a lot! 😀

Avatar image for Cavalcante

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.

Avatar image for amirrastkhadiv

amirrastkhadiv on April 7, 2021

That’s informative. Thanks Dan!

Avatar image for Espius Edwards

Espius Edwards on Sept. 3, 2021

Thank you for your concise tutorial!

Avatar image for François 江戸 D

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

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

Avatar image for MakerMike369

MakerMike369 on March 7, 2022

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

Avatar image for mckown

mckown on June 30, 2022

Excellent presentation! I learned quite a bit. Thanks!

Become a Member to join the conversation.