Closures are easier in VBA. It's called a static variable. No need for child functions. It's just a normal function-scoped variable who's value persists between calls.
I like this kind of games example where we keep refactoring the code as we learn more and more. 16:23 Unless it's intended I think there is no need for " " in lines 62 and 63 (Trying to save some spaces😁) Thanks Dave,
Total preference of spacing. I like to keep the lines separated, but you can go either way you prefer. Thanks Ahmad! I'm glad you like how we keep refactoring the example. 🚀
@@DaveGrayTeachesCode Fair enough, Refactoring gives me a sense of satisfaction that the work has been done but there is room for some improvements (although this is not always the case)
@Google Personal Maybe I missed that that. I don't know why you're interested in my last name, anyway, it's Murey not Murery and it's an Arabic male name and it can mean several things such as: What is nurtured, what is observed, protected, preserved, valued, protected, submissive, watched
Funny you should mention that because formatting strings - specifically f-Strings - is the next lesson in the series. Older methods like format() and %s are also covered.
How is this useful? It would seem to be similar to a class but only one method is allowed to be used. The function variable is initialized with 3 coins. Is it simply to set initial values, then make changes to the values as the closure function is called? To count something up? or down? Such as the amount of coins.
09:36 I made small changes and I think closure is more like OOP classes but In FP way :D """ def new_amusement_arcade(name='anonymous', coins=0): def play_game(): nonlocal coins coins -= 1 print(f' {name} has {coins} {"coin" if coins == 1 else "coins"} left.' if coins >= 1 else f' {name} is out of coins.') return play_game tommy_play_game = new_amusement_arcade(name="Tommy", coins=3) jenny_play_game = new_amusement_arcade(name="Jenny", coins=5) tommy_play_game() tommy_play_game() jenny_play_game() tommy_play_game() """
A clear description and example of closures, which can be very confusing at first when you're a beginner.
Glad it was helpful!
4:17 If you know there's exactly one coin, you don't have to say
str(coins)
you can just say
one
Very informative video, thank you!
thank you mr dave i learned a lot from you
Glad to hear that!
clojure hype!
Closures are easier in VBA. It's called a static variable. No need for child functions. It's just a normal function-scoped variable who's value persists between calls.
thank dave
I like this kind of games example where we keep refactoring the code as we learn more and more.
16:23 Unless it's intended I think there is no need for "
" in lines 62 and 63 (Trying to save some spaces😁)
Thanks Dave,
Total preference of spacing. I like to keep the lines separated, but you can go either way you prefer. Thanks Ahmad! I'm glad you like how we keep refactoring the example. 🚀
@@DaveGrayTeachesCode Fair enough,
Refactoring gives me a sense of satisfaction that the work has been done but there is room for some improvements (although this is not always the case)
@Google Personal Maybe I missed that that.
I don't know why you're interested in my last name, anyway, it's Murey not Murery and it's an Arabic male name and it can mean several things such as:
What is nurtured, what is observed, protected, preserved, valued, protected, submissive, watched
@Google Personal it's مرعي but I couldn't find a better way to pronounce it in English and I could be wrong
As perfect as usual!
Thank you!
Isn't it faster and easier to use .format() instead of concatenating strings (@3:43)?
Funny you should mention that because formatting strings - specifically f-Strings - is the next lesson in the series. Older methods like format() and %s are also covered.
@@DaveGrayTeachesCode it is a great series - thank you for doing it!
Appreciate you, Sir!
Thank you!
Hi! Can you make a video on calculation a cube volume, plotting it and rotating horizontally 360 degree? That will be helpful...
How is this useful? It would seem to be similar to a class but only one method is allowed to be used. The function variable is initialized with 3 coins. Is it simply to set initial values, then make changes to the values as the closure function is called? To count something up? or down? Such as the amount of coins.
Will you provide full python course ? because I want to follow this playlist
Please sir reply me
Yes, this playlist is building a full course. When complete, I usually release a compilation of the full course in one video, too.
@@DaveGrayTeachesCode Thank u sir for reply. And I am your big fan and I am from India
Thank You, Sir.
Welcome!
Using an f-string would have been much simpler in the print statement.
The rest of your explanation was very good.
very cool
Right on!
Finally
09:36
I made small changes and I think closure is more like OOP classes but In FP way :D
"""
def new_amusement_arcade(name='anonymous', coins=0):
def play_game():
nonlocal coins
coins -= 1
print(f'
{name} has {coins} {"coin" if coins == 1 else "coins"} left.' if coins >= 1 else f'
{name} is out of coins.')
return play_game
tommy_play_game = new_amusement_arcade(name="Tommy", coins=3)
jenny_play_game = new_amusement_arcade(name="Jenny", coins=5)
tommy_play_game()
tommy_play_game()
jenny_play_game()
tommy_play_game()
"""