Python Closures for Beginners | Python tutorial

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

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.

⭐ Become a full-stack dev with Zero To Mastery Courses:

👇 Follow Me On Social Media:

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:

Was this Python Closures tutorial for beginners helpful? If so, please share. Let me know your thoughts in the comments.

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

A clear description and example of closures, which can be very confusing at first when you're a beginner.

andrewclarke
Автор

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.

johnaweiss
Автор

4:17 If you know there's exactly one coin, you don't have to say
str(coins)
you can just say
one

johnaweiss
Автор

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 "\n" in lines 62 and 63 (Trying to save some spaces😁)
Thanks Dave,

ahmad-murery
Автор

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.

kevinerose
Автор

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'\n{name} has {coins} {"coin" if coins == 1 else "coins"} left.' if coins >= 1 else f'\n{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()
"""

willyhorizont
Автор

Hi! Can you make a video on calculation a cube volume, plotting it and rotating horizontally 360 degree? That will be helpful...

mohammedaljaf
Автор

thank you mr dave i learned a lot from you

khalilbenmeziane
Автор

Using an f-string would have been much simpler in the print statement.

kilianklaiber
Автор

Will you provide full python course ? because I want to follow this playlist
Please sir reply me

Nihal