Today I Discovered Something New in Python #python #pythonprogramming #learnpython

preview_player
Показать описание
Today I discovered something new in Python. #python #pythonprogramming #learnpython
Рекомендации по теме
Комментарии
Автор

Makes sense when you consider that objects in python are always passed by reference and the list is only storing a reference to itself, I bet a lot of other languages handle it the same way. It's not much different than assigning self to a property of an object during init. You should probably avoid using it ever since it will break any method that steps into a list recursively, like flattening a list.

mattbarker
Автор

This is interesting what if you want to yield from this list ?

alexandarjelenic
Автор

There's a similar but more useful thing with types, where you can say e.g. type Directory = list[File | Directory] to include arbitrarily nested instances of the thing you're defining

jamesarthurkimbell
Автор

The list being a reference, a number pointing to a place in memory (and other metadata), makes this possible. It's also interesting how the to_string method checks if the pointer element is the same as the current list element, so it returns an ellipsis instead of calling itself infinitely.

valcubeto
Автор

It's interesting; we have not encountered this till now. We would love to deep dive into its concepts; kindly make a video on the same.

ANANDVASHISHTHA-oi
Автор

I wonder how it's implemented, and if it works in all places and with all reasonable combinations of standard container types

vytah
Автор

Wooow, awesome, please make a detailed video about it

Ironnman
Автор

Never seen this. Nice that Python detects this and avoids getting into an infinite loop. I wonder what happens if you have a loop of references? Does it show that when it first hits an object it already printed?

TheJaguar
Автор

Damm, didn't know about it Thanks!

viddeshk
Автор

Hm. Maybe make two lists, a and b, and append each to both?

OneWeirdDude
Автор

I noticed you changed from pycharm to zed. I’ve been loving using that editor 😊

theme
Автор

Why are referring to it by python index rather than cardinal index

PolargeddonYT
Автор

I don't think there is much practical use for that behavior (but maybe I am wrong). It sure looks like an unintentional consequence of referencing by memory address.

Bolsonaro_em_Haia
Автор

How to make an object impossible for the garbage collector to delete it automatically (ref count never goes to zero).

davidt
Автор

if you look into the runtime method of a function(also treat as an object in python), you will find __call__ method of it. since __call__ its own is a function too, it has __call__ too. and in debugger you will find infinite recursive __call__.

KuRRe
Автор

It a clue to how classes work in python…

IBH
Автор

why do the fonts on mac os look so smooth damn why cant we have that on windows

thelavagod
Автор

This is normal in any programming language.

Grimlock
Автор

What if we try to yield it using a generator?

thegreekgoat
Автор

mcoding has a nice video about this and things like a = a[0] = [0]

bengski
visit shbcf.ru