Python Closures for Beginners | Python tutorial

  Рет қаралды 7,591

Dave Gray

Dave Gray

Күн бұрын

Пікірлер: 34
@andrewclarke6916
@andrewclarke6916 Жыл бұрын
A clear description and example of closures, which can be very confusing at first when you're a beginner.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Glad it was helpful!
@johnaweiss
@johnaweiss 7 ай бұрын
4:17 If you know there's exactly one coin, you don't have to say str(coins) you can just say one
@muzhaffarhaydar7928
@muzhaffarhaydar7928 Ай бұрын
thank dave
@johnaweiss
@johnaweiss 7 ай бұрын
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.
@kamranzamanni6826
@kamranzamanni6826 7 ай бұрын
Very informative video, thank you!
@ahmad-murery
@ahmad-murery Жыл бұрын
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,
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
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. 🚀
@ahmad-murery
@ahmad-murery Жыл бұрын
@@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)
@ahmad-murery
@ahmad-murery Жыл бұрын
@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
@ahmad-murery
@ahmad-murery Жыл бұрын
@Google Personal it's مرعي but I couldn't find a better way to pronounce it in English and I could be wrong
@mohammedaljaf6210
@mohammedaljaf6210 Жыл бұрын
Hi! Can you make a video on calculation a cube volume, plotting it and rotating horizontally 360 degree? That will be helpful...
@khalilbenmeziane8836
@khalilbenmeziane8836 Жыл бұрын
thank you mr dave i learned a lot from you
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Glad to hear that!
@kevinerose
@kevinerose 7 ай бұрын
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.
@GregPeters1
@GregPeters1 Жыл бұрын
Appreciate you, Sir!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you!
@alexanderkomanov4151
@alexanderkomanov4151 Жыл бұрын
As perfect as usual!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you!
@utinthein7274
@utinthein7274 Жыл бұрын
Thank You, Sir.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Welcome!
@willyhorizont8672
@willyhorizont8672 Жыл бұрын
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() """
@dickschweiger289
@dickschweiger289 9 ай бұрын
Excelent
@diewahrheituberfakten4800
@diewahrheituberfakten4800 Жыл бұрын
Isn't it faster and easier to use .format() instead of concatenating strings (@3:43)?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
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.
@diewahrheituberfakten4800
@diewahrheituberfakten4800 Жыл бұрын
@@DaveGrayTeachesCode it is a great series - thank you for doing it!
@kilianklaiber6367
@kilianklaiber6367 2 ай бұрын
Using an f-string would have been much simpler in the print statement.
@kilianklaiber6367
@kilianklaiber6367 2 ай бұрын
The rest of your explanation was very good.
@Nihal0522
@Nihal0522 Жыл бұрын
Will you provide full python course ? because I want to follow this playlist Please sir reply me
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Yes, this playlist is building a full course. When complete, I usually release a compilation of the full course in one video, too.
@Nihal0522
@Nihal0522 Жыл бұрын
@@DaveGrayTeachesCode Thank u sir for reply. And I am your big fan and I am from India
@road2hell46
@road2hell46 Жыл бұрын
very cool
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Right on!
@sokchamrernheng4216
@sokchamrernheng4216 Жыл бұрын
Finally
Python Scope tutorial for Beginners
19:50
Dave Gray
Рет қаралды 7 М.
Now it’s my turn ! 😂🥹 @danilisboom  #tiktok #elsarca
00:20
Elsa Arca
Рет қаралды 12 МЛН
Underwater Challenge 😱
00:37
Topper Guild
Рет қаралды 47 МЛН
SCHOOLBOY. Мама флексит 🫣👩🏻
00:41
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 6 МЛН
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 15 МЛН
5 Good Python Habits
17:35
Indently
Рет қаралды 521 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
Python Modules for Beginners
18:03
Dave Gray
Рет қаралды 9 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 110 М.
Python File Handling for Beginners
22:40
Dave Gray
Рет қаралды 13 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 400 М.
Modern Python logging
21:32
mCoding
Рет қаралды 183 М.
Learn Closures In 13 Minutes
13:22
Web Dev Simplified
Рет қаралды 66 М.
Python Generators Explained
28:37
Tech With Tim
Рет қаралды 154 М.
Now it’s my turn ! 😂🥹 @danilisboom  #tiktok #elsarca
00:20
Elsa Arca
Рет қаралды 12 МЛН