https://dbader.org/python-tricks ► String conversion in Python classes and other advanced OOP techniques When you define a custom class in Python and then try to print one of its instances to the console (or inspect it in an interpreter session) you get a relatively unsatisfying result. The default "to string" conversion behavior is basic and lacking in detail. By default all you get is a string containing the class name and the `id` of the object instance (which is the object's memory address in CPython). That's better than *nothing*, but it's also not very useful. The solution here is adding the `__str__` and `__repr__` "dunder" methods (some call them "magic methods") to your class. They are the Pythonic way to control how objects are converted to strings in different situations. In this tutorial video I'll do a deep dive on how Python's to-string conversion works and how you can add it to your own custom classes. I'll walk you through the __str__ and __repr__ methods, when to use each, and some tips on how to use them in real world scenarios. Just remember: * The result of `__str__` should be readable. * The result of `__repr__` should be unambiguous. * Always add a `__repr__` to your classes. The default implementation for `__str__` just calls `__repr__`, so you get the best of both worlds. To learn how to use the full potential of Python check out "Python Tricks: The Book" at the link below: https://dbader.org/pytricks-book FREE COURSE – "5 Thoughts on Mastering Python" https://dbader.org/python-mastery PYTHON TRICKS: THE BOOK https://dbader.org/pytricks-book SUBSCRIBE TO THIS CHANNEL: https://dbader.org/youtube * * * ► Python Developer MUGS, T-SHIRTS & MORE: https://nerdlettering.com FREE Python Tutorials & News: » Python Tutorials: https://dbader.org » Python News on Twitter: https://twitter.com/@dbader_org » Weekly Tips for Pythonistas: https://dbader.org/newsletter » Subscribe to this channel: https://dbader.org/youtube
https://dbader.org/python-tricks ► Master OOP techniques in Python with bite-sized code examples What's the difference between @classmethod, @staticmethod, and
Visit http://python.cogsci.nl/ for more tutorials! Seven solutions to common small problems that Python programmers often solve in a suboptimal way. This video
https://dbader.org/python-tricks ► Discover Python's advanced features and how to use them to your advantage The "with" statement in Python is regarded as an o
https://dbader.org/python-tricks ► Write clean and testable Python command line apps and learn by example Two techniques for writing automated tests for your P
A review of Apple's 2017 MacBook Pro 13-inch (no Touch Bar) from a software developers perspective. ► Best-fitting Sleeve for the MacBook Pro 13in (2017): http
https://dbader.org/python-tricks ► See how to leverage Python's best features, like List Comprehensions, in your own programs This video tutorial breaks down P
In this Python Programming Tutorial, we will be learning about iterators and iterables. There is a lot of confusion around these terms and exactly what they mea
https://dbader.org/python-tricks ► Master advanced features in Python with free & easy to digest code examples We're going to pry apart this slightly unintuiti
In this video, we will take a look at a common conditional statement in Python: if __name__ == '__main__': This conditional is used to check whether a python m
https://dbader.org/python-tricks ► Get examples of clean and Pythonic code that passes any Pylint or PEP 8 run. In this Pylint tutorial video you'll see how to
https://dbader.org/python-tricks ► Write clean & Pythonic code and start using advanced features in your Python code It's easy to get tripped up by Python's "i
An intro to functional programming in Python 3 covering Lambda, Map, Filter and Reduce functions. ► Python Lambda Functions: https://youtu.be/Ob9rY6PQMfI ► Lam
Python is a great programming language and if you have decided that you will learn python in 2019, that's a great choice. Python is great for web scrapping, an
https://dbader.org/python-tricks ► See how to emulate switch/case statements in Python and other "tricks" for advanced Pythonistas Python doesn't have switch/c
This video demonstrates the concept behind the conditional statement: if __name__ == "__main__" Explore my tutorials: https://www.indianpythonista.tech/tutori
Classes are a fundamental part of modern programming languages. Python makes it easy to make a class and use it to create objects. Today you will learn the es
In this Python Object-Oriented Tutorial, we will be learning about the property decorator. The property decorator allows us to define Class methods that we can
In this Python Tutorial, we will be learning how to read and write to files. You will likely come into contact with file objects at some point while using Pytho
This video tutorial looks at the use of the Python __init__ method used when writing classes from which objects are created and then initialized.