What Are * and / Parameters in Python Functions?

preview_player
Показать описание
Today we learn about the special Python function parameters * (asterisk) and / (slash).

◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚

💼 Services 💼

🌐 Social Media & Contact 🌐
Рекомендации по теме
Комментарии
Автор

What a handy way of reducing the readability of code...

thenerdyouknowabout
Автор

Never knew python has this functionality. Thank you

qppsbkb
Автор

I like defining the arguments coming in and then passing them in with their name/value pairs so there's no confusion this function takes these things.

Websitedr
Автор

sidenote: its usually one or the other not both in one function although you can use both at the same time.

amortalbeing
Автор

I think that in 99 / 100 cases these are a bad thing to use.

Any time i make a program or library, i only push it out into the wild once it's a semi-polished diamond.

So restricting which method of calling functions people want to do seems only useful for core python libraries or nuclear power plant level type stuff.

The / does help at avoiding breaking changes (as noted in the video) but it also forces users to write worse code, which could be affected by people swapping around arguments in the function name.

If a function name loses a bunch of parameters, it could still end up breaking a user's program.

I still think it's a really good video, since now i know what to do whenever i see this in a codebase and kwargs aren't accepted 😈

Walter_
Автор

did someone run out of ideas for adding new python features?

StefaanHimpe
Автор

the asterisk seems to work somewhat similarly to *args. You can have any amount of *args, so the only way to pass arguments that go after *args and let the function know what they are is to specify them as keywords.

zokalyx
Автор

you could have disabled your IDE's parameter hints, because seeing p1=20 being replaced by p1;20 isn't really easy to understand when you don't know what's going on....

crixi__
Автор

2:42 The only good thing is it's great ability to make it so that the company can't hire anyone else as no one else will understand what your wrote, so your aren't replaceable.

SrijalPlayz
Автор

Slightly confused by those parameters names followed by a colon. Is that just something your editor shows ?

jms
Автор

Thanks a ton, I knew about star but not /!

iyadahmed
Автор

Thanks for this good video on this esoteric python functionality. It seems python has "jumped the shark" by adding cruft for edge-case use. I prefer to stay away from using these parameters, unless I really, really need them, as it makes the code less readable. Eventually, languages and everything in life adds all these specialty items, like all the kitchen gadgets one can acquire instead of simply having general purpose kitchen tools. Egg timers are great for people who boil eggs all the time, but if you do it once per year, skip it.

ytlongbeach
Автор

Would like a lot a series on Python reflex library

Aletranzocchi
Автор

Adding a new feature to Rust: No that'll add too much bikeshedding
Adding a new feature to Python:

Ztaticify
Автор

Holy... That's just in time... In my code I want to make sure that arguments should be called as keyword arguments for "security" reasons (rejecting wrong interface usage out of pipelines).

ucwolct
Автор

Hey, just had a completely different question, how can I get that keyword showing when calling a function like p1:10 in nvim? I see u use pycharm or something but is it possible on nvim?

kshitijaucharmal
Автор

Cool! Does it also exist in python 2.7?

rondamon
Автор

What is that prefix-colon thing, like print(p1:10) ? I've never seen it before and it's a syntax error in my CLI.

Risuchan
Автор

apart from restricting usage, is there any other efficiency benefit to using * or /?

SBalajii
Автор

What is this theme? It looks kinda like One Dark Pro but with a few colors changed

peter_c_