- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
The Python Trap That Catches EVERY Beginner! #shorts
Can you guess what this Python code prints?
python:
def add_item(item, items=[]):
items.append(item)
return items
print(add_item(1))
print(add_item(2))
This is one of Python's most famous gotchas - the mutable default argument trap! Default mutable arguments like lists and dictionaries are created ONCE when the function is defined, not each time it's called. This means the same list is shared between all function calls!
The fix? Use None as the default and create a new list inside the function:
def add_item(item, items=None):
if items is None:
items = []
items.append(item)
return items
Follow @GoCelesteAI for more coding quizzes and programming tips!
#python #programming #coding #developer #programmer #tech #codingquiz #pythontips #learnpython #softwareengineering #codetest #interviewquestions #shorts
python, programming, coding, developer, programmer, tech, codingquiz, pythontips, learnpython, softwareengineering, codetest, interviewquestions, shorts, mutable default arguments, python gotchas, python bugs, python interview, coding challenge
Видео The Python Trap That Catches EVERY Beginner! #shorts канала Taught by Celeste AI - AI Coding Coach
python:
def add_item(item, items=[]):
items.append(item)
return items
print(add_item(1))
print(add_item(2))
This is one of Python's most famous gotchas - the mutable default argument trap! Default mutable arguments like lists and dictionaries are created ONCE when the function is defined, not each time it's called. This means the same list is shared between all function calls!
The fix? Use None as the default and create a new list inside the function:
def add_item(item, items=None):
if items is None:
items = []
items.append(item)
return items
Follow @GoCelesteAI for more coding quizzes and programming tips!
#python #programming #coding #developer #programmer #tech #codingquiz #pythontips #learnpython #softwareengineering #codetest #interviewquestions #shorts
python, programming, coding, developer, programmer, tech, codingquiz, pythontips, learnpython, softwareengineering, codetest, interviewquestions, shorts, mutable default arguments, python gotchas, python bugs, python interview, coding challenge
Видео The Python Trap That Catches EVERY Beginner! #shorts канала Taught by Celeste AI - AI Coding Coach
Комментарии отсутствуют
Информация о видео
18 января 2026 г. 21:44:15
00:00:46
Другие видео канала
























