Тёмный
No video :(

What Are * and / Parameters in Python Functions? 

NeuralNine
Подписаться 364 тыс.
Просмотров 41 тыс.
50% 1

Today we learn about the special Python function parameters * (asterisk) and / (slash).
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine...
💻 The Algorithm Bible Book: www.neuralnine...
👕 Programming Merch: www.neuralnine...
💼 Services 💼
💻 Freelancing & Tutoring: www.neuralnine...
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine...
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/Neu...
🎙 Discord: / discord

Опубликовано:

 

29 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 67   
@thenerdyouknowabout
@thenerdyouknowabout 5 месяцев назад
What a handy way of reducing the readability of code...
@robertvangeel3599
@robertvangeel3599 5 месяцев назад
Excellent comment
@user-hx8hq4st3r
@user-hx8hq4st3r Месяц назад
Right, any beginner will find it very difficult to understand.
@user-qp2ps1bk3b
@user-qp2ps1bk3b 6 месяцев назад
Never knew python has this functionality. Thank you
@Websitedr
@Websitedr 6 месяцев назад
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.
@amortalbeing
@amortalbeing 6 месяцев назад
sidenote: its usually one or the other not both in one function although you can use both at the same time.
@crixi__
@crixi__ 5 месяцев назад
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....
@Walter_
@Walter_ 6 месяцев назад
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 😈
@georgerogers1166
@georgerogers1166 6 месяцев назад
/ args are helpful when you have a optional positional argument, and a **args parameter.
@Primeagen
@Primeagen 6 месяцев назад
/ is useful in range type of functions, where number of arguments change the meaning of parameter. Like in range(a), a is the upper limit but in range(a, b), a is the lower limit
@zokalyx
@zokalyx 5 месяцев назад
I agree that python has many features that are easy to abuse, but overall they can be greatly beneficial if applied correctly.
@zokalyx
@zokalyx 5 месяцев назад
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.
@user-hx8hq4st3r
@user-hx8hq4st3r Месяц назад
Yes,That’s the text book definition
@StefaanHimpe
@StefaanHimpe 5 месяцев назад
did someone run out of ideas for adding new python features?
@jms019
@jms019 6 месяцев назад
Slightly confused by those parameters names followed by a colon. Is that just something your editor shows ?
@tubero911
@tubero911 6 месяцев назад
Yes, they are PyCharm inlay hints. I can see how they would confuse the majority of viewers, who are not JetBrains users.
@ytlongbeach
@ytlongbeach 6 месяцев назад
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.
@mikejhibbard
@mikejhibbard 5 месяцев назад
An example of what Nassim Taleb calls “the tyranny of the minority” - also why all fried chicken shops use Halal meat even though only a small minority of customers demand it
@SrijalPlayz
@SrijalPlayz 5 месяцев назад
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.
@user-uc6wo1lc7t
@user-uc6wo1lc7t 6 месяцев назад
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).
@bradentoone895
@bradentoone895 6 месяцев назад
For everyone asking when this is actually useful: I use this whenever attempting to mimic other language’s signature overrides. This way you can combine multiple different function signatures under the same name but have separate “pathways”. I.E def foo(x: int , /, y: Any, *, z: str) could let you provide different control flows given a combination of parameters given
@tanuj05
@tanuj05 5 месяцев назад
Never knew about this , thanks !
@Risu0chan
@Risu0chan 5 месяцев назад
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.
@disres1337
@disres1337 5 месяцев назад
Its not actual syntax, its just the editor/ide highlighting which parameter it is assigned to
@Ztaticify
@Ztaticify 5 месяцев назад
Adding a new feature to Rust: No that'll add too much bikeshedding Adding a new feature to Python:
@SBalajii
@SBalajii 6 месяцев назад
apart from restricting usage, is there any other efficiency benefit to using * or /?
@Michallote
@Michallote 5 месяцев назад
Technically you are affecting the function signature. So additional checks are enforced when calling the function, which means it actually takes more clockcycles to run. So it's not about efficiency, it's about enforcing behaviour
@SBalajii
@SBalajii 5 месяцев назад
@@Michallotemakes sense, thanks
@TheCircuitProject
@TheCircuitProject 6 месяцев назад
Great tutorial, thanks man!
@ashishm8850
@ashishm8850 6 месяцев назад
Excellent, as always 👍
@davidmurphy563
@davidmurphy563 6 месяцев назад
In decades of coding I've never seen / or * once used for real the wild*. I wonder if there's anyone that will ever watch this video that has. *not including *args, **kwargs which are everyday ofc
@NeuralNine
@NeuralNine 6 месяцев назад
I actually saw it for the first time in a code base I recently started working on, which is why I made this video.
@user-zp2hu2wz1f
@user-zp2hu2wz1f 6 месяцев назад
one can observe these commonly in built-ins, expecially typing module
@davidmurphy563
@davidmurphy563 6 месяцев назад
@@user-zp2hu2wz1f Explains a lot, that's the one python module I've never used! Python boilerplate bloat module! ;)
@strophariacaerulea
@strophariacaerulea 6 месяцев назад
* is actually all over the pandas source code to ensure they can freely change signatures after the core params like self and other without breaking everybody's code.
@davidmurphy563
@davidmurphy563 6 месяцев назад
@@strophariacaerulea Ah, is it really? That's interesting. I use pd all the time but I'll confess I've never looked at the source. Hold on, I'll jump onto github and take a look. Hmm. Got bored before I found an example. Anyway, I'm sure it's there and I just missed it, it's a big old project.
@rondamon4408
@rondamon4408 5 месяцев назад
Cool! Does it also exist in python 2.7?
@Ilhom_Rustamov
@Ilhom_Rustamov 6 месяцев назад
Bro, excellent! I am a subscriber from Uzbekistan. You always teach us the best things about python. Good luck Bro!
@Aletranzocchi
@Aletranzocchi 6 месяцев назад
Would like a lot a series on Python reflex library
@ChrisHalden007
@ChrisHalden007 6 месяцев назад
Very useful. Thanks
@darcash1738
@darcash1738 5 месяцев назад
quick summary: Slash (/): Makes everything before it a forced positional arg Asterisk (*): Makes everything after it a forced kwarg # Ex1 def func(param1, param2, /, param3): # Will make param1 and 2 forced positional pass # Ex2 def func(param1, param2, *, param3): # Will make param3 forced key word arg pass # Ex 3 def func(p1, p2, /, p3, *, p4): # p1 and p2 are forced positional, and p4 is forced kwarg. pass # Came up with this extra example myself when wondering what would happen if they overlap: # Ex 4 def func(p1, *, p2, p3, p4, /, p5): # When combined and conflicting, asterisks are more powerful pass func(1, p2=2, p3=3, p4=4, p5=5) # p1 is forced positional, the rest are forced key word args.
@__christopher__
@__christopher__ 5 месяцев назад
I'm surprised that the last isn't simply an error. After all it says that p2 to p4 are allowed to be neither positional nor keyword arguments, which cannot be. And the actual functionality can easily be achieved by just following the slash immediately by the star, so there's no no point in supporting that illogical syntax.
@darcash1738
@darcash1738 5 месяцев назад
@@__christopher__ yeah pretty funny how it works. It makes sense though since kwargs need to go after args. I also expected an error lmao
@peter_c_
@peter_c_ 6 месяцев назад
What is this theme? It looks kinda like One Dark Pro but with a few colors changed
@uuuummm9
@uuuummm9 6 месяцев назад
I did not know about this!
@mikejohnston9113
@mikejohnston9113 6 месяцев назад
Thank you
@kshitijaucharmal145
@kshitijaucharmal145 6 месяцев назад
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?
@Naej7
@Naej7 5 месяцев назад
Don’t use nvim :^)
@lord.farquaad11
@lord.farquaad11 6 месяцев назад
what version of python was this introduced?
@mentalverse7837
@mentalverse7837 6 месяцев назад
U r da best
@dieginin
@dieginin 6 месяцев назад
bro you’re the best, thanks
@umeshprajapati7149
@umeshprajapati7149 6 месяцев назад
When will you upload flask 3rd Tutorial
@NeuralNine
@NeuralNine 6 месяцев назад
The current schedule is two Flask episodes, two general episodes, two Flask episodes etc.
@supercompooper
@supercompooper 6 месяцев назад
This is a wretched syntax
@MJ-cf9nl
@MJ-cf9nl 3 месяца назад
I never knew or remembered this functionality in Python, thus never used it or had the need for it. This is another example of adding junk to a language that has no semantic purpose or need for. I mean all programming languages pass arguments to functions based on the order of the parameters defined in the method signature.... simple as that
@daveduvergier3412
@daveduvergier3412 5 месяцев назад
None of the putative uses for these things are compelling - just seem like needless complications all round.
@funprog
@funprog 5 месяцев назад
This certainly bug inducing behaviour and violates the keep it simple principle. Don't recommend using such corner cases.
@venil82
@venil82 6 месяцев назад
this is useful knowledge, but not very useful functionality from python I'd rather python spent effort in being less verbose
@Naej7
@Naej7 5 месяцев назад
Using * is actually a good practice It’s not about verbosity, it’s about maintainability
@tiruialon
@tiruialon 5 месяцев назад
I have to say, this has got to be the dumbest anti-feature I have ever seen. The ability to take away disambiguation is never a good idea. It's paired a horrible syntax too: passing math operators as standalone arguments is not a concept anyone can understand without a thorough explanation.
@erichlf
@erichlf 6 месяцев назад
Definitely code smell.
@Naej7
@Naej7 5 месяцев назад
Using * is actually a really good practice
@TimoYlhainen
@TimoYlhainen 6 месяцев назад
Python. Meh.
@LennyHirsch
@LennyHirsch 5 месяцев назад
What’s wrong with python?
Далее
Debugging 101: Replace print() with icecream ic()
12:36
5 Useful Python Decorators (ft. Carberra)
14:34
Просмотров 98 тыс.
Functions vs Classes: When to Use Which and Why?
10:49
Просмотров 153 тыс.
Deques can be FASTER than lists in Python
12:17
Просмотров 26 тыс.
5 Tips To Write Better Python Functions
15:59
Просмотров 103 тыс.
Modern Python logging
21:32
Просмотров 180 тыс.
*Args and **Kwargs in Python
3:49
Просмотров 269 тыс.
5 Good Python Habits
17:35
Просмотров 508 тыс.
Modern Graphical User Interfaces in Python
11:12
Просмотров 1,5 млн
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 802 тыс.
Advanced Exception Handling in Python
12:06
Просмотров 60 тыс.