You Can Do Really Cool Things With Functions In Python

preview_player
Показать описание

Here are a few not-so-common things you can do with functions in Python, including closures and partial function application. Functions are incredibly powerful and you can use them to write code that's really clean and often a lot shorter than when relying on classes and object-oriented programming.

🔖 Chapters:
0:00 Intro
1:32 Explaining the code example
3:56 About the Strategy pattern
4:29 Replacing the class structure by functions
9:24 Passing extra parameters using closures
13:37 Using partial functions

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

It's really cool to watch your videos, because they open our minds to other possibilities of how to build the same code. You teach things that are not easy to find anywhere else.

davia.sampaio
Автор

You sir, are putting out the best Python content on the internet. Thank you!

fschlz
Автор

Little Vim tip: full stop (.) repeats your last action. This includes entering insert mode and typing things. e.g. at 6:10 you type out "_avg" twice. You could instead just type it once, navigate to the next function, then press . and that'll type out "_avg" again for you. Same with _minmax a few seconds later!

Edit: Just watched the part about partial functions. Can't believe I've never seen them before, they seem like such a useful tool!

alira
Автор

Great video, Arjan. I also use the functools a lot, e.g. partial. What I really love about Python is that it supports many different approaches and does not force you to use a single one. As a developer I can choose between many different approaches, and choose the one that I think is the best to solve my current problem. Python lets me express myself in code directly in various ways.

robertbrummayer
Автор

I guess it matters how you define the function of the bread. I may be partial to German bread and will happily eat it by itself, but there's an argument to be made that, say, certain French breads shine as part of a breakfast. With American bread, islice it and toast it and it slaps. Italian bread is in a class of its own. I haven't tried Dutch bread, I gotta find some, I wonder if they import it here. And to give y'all some closure, I'm sure any bread from any country can be great if combined with the right ingredients

ExplicableCashew
Автор

This came in handy for my weekend project! I’ve watched through all your Python videos so far, and my code has started to improve dramatically as a result. Thanks for sharing!

raeganb.
Автор

wow. I am currently working on a project where I use functions that return customized functions, just as in your example. So partial just blew my mind a little. Thank you so much for introducing this awesome tool to me :)

MisterMobius
Автор

One of the greatest videos I've seen from your YouTube channel, Arjan! Thanks for it.

danyalt
Автор

Thank you for your time and patient, the DOC contains a beautiful explanation in 7 steps about design better.

rolandovillcaarias
Автор

I’ve been living in the Netherlands for 3 years and you are the first dutch that I know that doesn’t like sliced bread 🤣

Very good video, as usual!

eduardomoraes
Автор

man your channel is underrated!! you are really provide a high quality contents with a great knowledge and experience, partial function are awesome i need to use it more, thank you.

exganza
Автор

functools is amazing. Besides partial there is also reduce, wraps and lru_cache which I use all the time. singledispatch can also be nice in very simple cases but it quickly hits a roadblock in more complex scenarios.

XRay
Автор

I really like how your tutorials have never been completely OOPs. A functional-leaning python programmer is a rarity :D I wonder if you have a playlist of videos on functional-ish concepts. The way you describe things is perfectly applicable and would be a very clean and organised way to write julia code as well.

smalltimer
Автор

Hi Arjan! Thanks for all your work teaching and coding! I came accross partial when I was working with python's multiprocessing library for performing a task with many files with some "standard" parameters that were the same for each and some "variable" parameters (such as the dataframe) that were unique to each process. This video gave me a better context of what partial actually is/does, and it's helping me with an NLP project refactor. 😄

prestonfrasch
Автор

Great video as always! Partials are nice. I wrote a validate(validate_func, data_type, data, ....) function that I could then call from a partial like validate_json = partial( validate, json.loads, "JSON")
or validate_uuid = partial(validate, uuid.UUID4, "UUID").

luandasilva
Автор

I've temporarily moved to Finland from the Netherlands, and I can confirm: the bread is better in the Netherlands.
There is a even bigger difference in cheese though: the cheese is horrible here.

Jorrit_
Автор

get_best_bread = partial(get_bread_from, country_code="de_DE") :) Great video! I was astounded seeing the closure part and then really impressed seing partial() in use. The flexibility and simplicity of providing values for named variables and using it on any function is amazing. My wife is gonna get jealous of the love I am developping for Python. Thanks for sharing this!

bartuslongus
Автор

you told me to buy Dutch bread after getting the free guide, but I see no link in video description for where to buy it, so I guess I will just keep living in my "bread fantasy world". Love your vids. They are always very informative. Thank you!

FirstLookVaper
Автор

Thank you for another great video Arjan! also, your anecdote reminded me of a similar pun "no matter how kind your kids are, German kids will always be kinder"

vladyn
Автор

While I don't follow everything you do, I like to watch your videos because it exposes me to new ways of thinking as well as showing me the practical reality of what is typed to accomplish an objective. Very cool indeed. :)

Whatthetrash