RUVIDEO
Поделитесь видео 🙏

Python string methods | Dunder methods

Interview Questions: python dunder, python str(), python str, python repr, python repr magic method, string python 3, python repr method, python repr vs string, python strip function, python dunder method, python repr dunder, dunder methods, repr string python, special methods, str string vs repr string, python __repr__, magic methods, python str dunder, python magic methods, python dunder methods, string python programming
, str string python, python to string, python str function, repr, python special methods, str in python, str() in python, __str__ in python, python __str__, __str__, __repr__

Python Notes:
In Python, dunder methods are methods that allow instances of a class to interact with the built-in functions and operators of the language. The word “dunder” comes from “double underscore”, because the names of dunder methods start and end with two underscores, for example __str__ or __add__. Typically, dunder methods are not invoked directly by the programmer, making it look like they are called by magic. That is why dunder methods are also referred to as “magic methods” sometimes.1

Why do dunder methods start and end with two underscores?
The two underscores in the beginning and end of the name of a dunder method do not have any special significance. In other words, the fact that the method name starts and ends with two underscores, in and of itself, does nothing special. The two underscores are there just to prevent name collision with other methods implemented by unsuspecting programmers.

Introduction to the Python __str__ method
Let’s start with the Employee class:

In Python, dunder methods are methods that allow instances of a class to interact with the built-in functions and operators of the language. The word “dunder” comes from “double underscore”, because the names of dunder methods start and end with two underscores, for example __str__ or __add__. Typically, dunder methods are not invoked directly by the programmer, making it look like they are called by magic. That is why dunder methods are also referred to as “magic methods” sometimes.1

Why do dunder methods start and end with two underscores?
The two underscores in the beginning and end of the name of a dunder method do not have any special significance. In other words, the fact that the method name starts and ends with two underscores, in and of itself, does nothing special. The two underscores are there just to prevent name collision with other methods implemented by unsuspecting programmers.

Example: class Employee:
def __init__(self, firstName, lastName):
self.firstName = firstName
self.lastName = lastName
def __repr__(self):
return f'Employee("{ self.firstName }","{ self.lastName }")'
def __str__(self):
return f'Employee({ self.firstName },{ self.lastName })'


e = Employee("Bill", "Gates")
print(e)

#pythontutorial
#pythoncourse
#learnpython
#pythonprojects
#pythonprogramming
#pythoncrashcourse
#pythonbasics
#pythonforbeginners
#pyhon
#pythonbeginners #magicmethods
#dundermethods
#str()


Channel: https://www.youtube.com/@NewsOnCoding
Python Playlist - https://www.youtube.com/channel/UC9Lbtd9MbEIoHln_XAgqD6A?sub_confirmation=1
? - FACEBOOK: https://www.facebook.com/profile.php?id=100094506555328

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Python string methods | Dunder methods», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.