Это видео недоступно.
Сожалеем об этом.
Python higher order functions 👑
HTML-код
- Опубликовано: 10 янв 2021
- Python higher order functions tutorial example explained
#python #higher-order #functions
Higher Order Function = a function that either:
1. accepts a function as an argument
or
2. returns a function
(In python, functions are also treated as objects)
---- 1. accepts a function as an argument ----
def loud(text):
return text.upper()
def quiet(text):
return text.lower()
def hello(func):
text = func("Hello")
print(text)
hello(loud)
hello(quiet)
----------- 2. returns a function ------------
#def divisor(x):
#def dividend(y):
#return y / x
#return dividend
#divide = divisor(2)
#print(divide(10))
Bro Code merch store 👟 :
===========================================================
teespring.com/...
===========================================================
music credits 🎼 :
===========================================================
Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
Free Download / Stream: bit.ly/2JnDfCE
Music promoted by Audio Library • Up In My Jam (All Of A...
===========================================================
# Higher Order Function = a function that either:
# 1. accepts a function as an argument
# or
# 2. returns a function
# (In python, functions are also treated as objects)
# ----- 1. accepts a function as an argument -----
def loud(text):
return text.upper()
def quiet(text):
return text.lower()
def hello(func):
text = func("Hello")
print(text)
hello(loud)
hello(quiet)
# ------------ 2. returns a function -------------
#def divisor(x):
#def dividend(y):
#return y / x
#return dividend
#divide = divisor(2)
#print(divide(10))
why diivde(10) and not dividend(10)
Thanks a bunch for the vid. It was really well explained with the examples!
Thank you, Nicely explained.
Very cool outro video, love it too.
Hello fellow coders I new and this was a very VIDEO helpful. oops returned Loud
I would always be grateful. For the last two days I had been stuck with decorators in python. You answered my question. 🌹 Thanks again.
1) Liked
2) Commented
3) Subscribed
Are you learning python in SoloLearn??
@@user-ce3vr2dp6i yes
NEED ASSISTANCE ASAP, FOR THE SECOND ONE....
how does divide(10) take the value to dividend(y)
heya, i had this issue too, after thinking for abit, I think i got it, let me try to explain:
after the line divide = divisor (2), x becomes 2 and it goes through the code, returning divident.
so now the next line, divide(10) can be read as divident(10) because it returned divident, thus y=10, hope it helps!
@@onlyLewds Thanks
Helped me out with returning HOF, btw your voice sounds like an almost perfect text to speech robot 🤣
Splendid, spend hrs with gpt bbut didnt get it, here 5 mins. I like this crazy function itself traveling hiding behind innocent variable name. Will make code looks simple but cant be copy pasted
superb explanation. Thnx bro
Simple nice introduction.
excellent free knowledge
yo the second example caught me off guard
Thanks
Bro, please add English subtitles, because it's only Vietnam. Lol
Thank you!
You are the best
Good content
i don't really understand the second example
he used function assigned to variable..the divisor(x=2) function returns dividend function.
and then he assigned this result to divide variable. now the dive variable is acting as the dividend function with argument of 10.hope i sound clear
@@manuelvaal1257 ty that makes more sense.
@@manuelvaal1257 thank you i understand your explanation
I cannot wrap my head around the first one. The second one makes more sense if you write it like this:
print(divisor(2)(10))
Very good!
wow thanks bro. I tried so hard to understand the logical of the 2nd one. but when I see your tips, it helps me a lot
Well explained. Thank you!
Good video
Thank You Sir
kinda mind boggling
Niceee man
Good video bro
Good stuff.
Great stuff, very good tutorial.
very useful, thanks
Here is my random comment for your BRO ❤
Thanks! I was srtuck on this
thx 4 vid bro !
Really useful
Thank you!
Thanks Bro
thank you so much!
Thank you
Thanks!
Wow!
Why on the first example the function is called with the () and how can we differentiate from a variable (as it could be mistaken by an variable)
thanks bro
I don't get the efficacy of this in the context of making code readable, Making less code maybe.
print(divisor(2)(10))
love u
Trippy stuff, but interesting
Man, I thought it called closure, is not it? (the seconds examp)
Does anyone has best playlist to learn react js
random comment ;)
higher order comment :P
drop a comment
Sreen is not clear
Thanks
Thanks!
Thank you
Thank you bro