Python Closures for Beginners | Python tutorial

  Рет қаралды 6,645

Dave Gray

Dave Gray

Күн бұрын

Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
Learn Python closures for beginners in this Python tutorial. Closures are a concept that can be difficult for beginners to understand, but this tutorial provides a memorable example of closure and applies closures to an application to show how they work.
💖 Support me on Patreon ➜ / davegray
⭐ Become a full-stack dev with Zero To Mastery Courses:
- The Complete Python Developer: bit.ly/CompPythonDev
- Complete Machine Learning & Data Science: bit.ly/CompMachineLearning
- Junior to Senior Dev Roadmap: bit.ly/WebDevRoadmap-JrtoSr
🚩 Subscribe ➜ bit.ly/3nGHmNn
📬 Course Updates ➜ courses.davegray.codes/
❓ Questions - Please post them to my Discord ➜ / discord
☕ Buy Me A Coffee ➜ www.buymeacoffee.com/davegray
👇 Follow Me On Social Media:
Github: github.com/gitdagray
Twitter: / yesdavidgray
LinkedIn: / davidagray
🔗 Source Code: github.com/gitdagray/python-c...
🔗 Playlist for this Python Course: bit.ly/dg-beginners-python
Python Closures tutorial for Beginners
(00:00) Intro
(00:05) Welcome
(00:13) Lesson Plan
(00:58) What is Closure?
(01:47) An Example of Closure
(08:47) Revisiting the Closure Definition
(09:37) Using a parameter value
(10:43) Closures help you avoid globals
(11:09) Applying closures to Rock-Paper-Scissors
📚 Tutorial References:
🔗 Python Official Site: www.python.org/
🔗Visual Studio Code Official Site: code.visualstudio.com/
Was this Python Closures tutorial for beginners helpful? If so, please share. Let me know your thoughts in the comments.
#python #closures #tutorial

Пікірлер: 33
@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 6 ай бұрын
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 5 ай бұрын
Very informative video, thank you!
@khalilbenmeziane8836
@khalilbenmeziane8836 Жыл бұрын
thank you mr dave i learned a lot from you
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Glad to hear that!
@alexanderkomanov4151
@alexanderkomanov4151 Жыл бұрын
As perfect as usual!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you!
@GregPeters1
@GregPeters1 Жыл бұрын
Appreciate you, Sir!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you!
@johnaweiss
@johnaweiss 6 ай бұрын
4:17 If you know there's exactly one coin, you don't have to say str(coins) you can just say one
@mohammedaljaf6210
@mohammedaljaf6210 Жыл бұрын
Hi! Can you make a video on calculation a cube volume, plotting it and rotating horizontally 360 degree? That will be helpful...
@dickschweiger289
@dickschweiger289 7 ай бұрын
Excelent
@utinthein7274
@utinthein7274 Жыл бұрын
Thank You, Sir.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Welcome!
@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
@kevinerose
@kevinerose 5 ай бұрын
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.
@road2hell46
@road2hell46 Жыл бұрын
very cool
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Right on!
@sokchamrernheng4216
@sokchamrernheng4216 Жыл бұрын
Finally
@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!
@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
@kilianklaiber6367
@kilianklaiber6367 10 күн бұрын
Using an f-string would have been much simpler in the print statement.
@kilianklaiber6367
@kilianklaiber6367 10 күн бұрын
The rest of your explanation was very good.
@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() """
Python Scope tutorial for Beginners
19:50
Dave Gray
Рет қаралды 6 М.
THE POLICE TAKES ME! feat @PANDAGIRLOFFICIAL #shorts
00:31
PANDA BOI
Рет қаралды 25 МЛН
КАРМАНЧИК 2 СЕЗОН 7 СЕРИЯ ФИНАЛ
21:37
Inter Production
Рет қаралды 551 М.
Python Modules for Beginners
18:03
Dave Gray
Рет қаралды 7 М.
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 53 М.
Demystifying Python Decorators || Decorators in Python
10:53
A Binary Code
Рет қаралды 193
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 277 М.
Python Dictionaries and Sets for Beginners | Python tutorial
29:54
Python Command Line Arguments tutorial for Beginners
21:25
Dave Gray
Рет қаралды 6 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 386 М.
THE POLICE TAKES ME! feat @PANDAGIRLOFFICIAL #shorts
00:31
PANDA BOI
Рет қаралды 25 МЛН