Navigate Select ESC Close

Never Use [ ] as a Default Argument in Python...

2026-05-27 Science & Technology
2.0k
181
7
NeuralNine
NeuralNine
470.0k subscribers

Unlock all features

FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.

Description

💻️ Need some help with a project or some consulting? Contact me here: https://www.neuralnine.com/services 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/

Top Comments (10)

@az8560 2026-05-27

that was a well thought language design decision for sure

1
@tropkal 2026-05-28

Never knew this about python, thank you so much for this video!

0
@10fonso 2026-06-03

I have in big programms very offen as default value at parameters [] (that for an programmer is the data type more intuitive clear), If you set anything at the optional parameter then know the programmer intuitive this must be a list. And only if a optimal argument is set 'work' internal a function with the list (e.g. create/return other list, or do willful manipulate the given list by side-effect). However, If you know what you do is the list at the parameter never manipulated. The exampe in the video ist a little "artifical", my opinion

0
@KrishnaShrimali-qf5hm 2026-05-29

Thank you so much

0
@k.chriscaldwell4141 2026-05-28

Thank you.

0
@Gigusx 2026-05-27

If we make a copy of the inventory (6:44), doesn't it make sense to go back to using an empty list as default argument for inventory?

1
@rebotIDD 2026-05-28

we need a video about RAGflow , please

0
@thomasgoodwin2648 2026-05-27

Brilliant, cut to the chase explanation as always. .👍👍 My easy way around the issue is to pass None as the default, and stuff the value later. def my_func (arg1: int = 0, arg2: [list | None] = None): real_arg2 = [] if arg2 is None else arg2 return real_arg2[arg1] I included type hinting out of good habit. Like most programming, there's more than one solution that often comes down to personal choice. As long as one is consistent, it's all good though. ❤❤❤ 🖖😎👍

0
@MaximosTheGamer 2026-05-27

can you make a course on backend web dev but with js now

0
@chaturvedikuldeep 2026-05-27

Good demonstration. And don't forget to mention about call by value and call by reference action happening under the hood.

6

Unlock the Data Inside
Turn Videos into Knowledge

  • Get FREE 10/day: transcripts, summaries, chats
  • Chat with videos, export text & PDF
  • $1 free API credit for RAG, chatbots & research

Free forever plan • All features unlocked

App screenshot