Local and Global Variable Scope in Python (Python for Beginners) | Part 16

preview_player
Показать описание
Enjoyed my video? Leave a like!
Рекомендации по теме
Комментарии
Автор

Thank you, Max! Your explanation was perfect!

ezrablack
Автор

Hello Max,
First of all you are doing a great job.

I rewrote this piece of code and my understanding is that scope() does not know any thing about variable x declared outside of it instead having permission issue.
Please note that I developed my understanding that any variable outside of function (unless that variable is passed as an argument or made global) has no idea about it.

and if i write my first statement to change x with in scope it would actually declare a new variable x having scope with in the scope funtcion.

This works fine
x="max"
print("first" + x)
def Scope():
x="haris"
print("sec" + x)
Scope()

but if i do like this it would error out not because of permission issue by rather scope of the variable.
x="max"
print("first" + x)
def Scope():
print(x)
x="haris"
print("sec" + x)
Scope()

abidalimushtaq
Автор

Why is global considered bad programming practice?

alfredoalejo
Автор

I don't get how x = whatever outside a function isn't a default global variable? I'm pretty sure in JS it is a global variable or a public variable.

BurtMeister
Автор

wait so is the first variable a global one or a local one

danz
Автор

What kind of a monster uses IDLE... Thanks for the video though. It was helpful

amorestperpe
Автор

Thanks Max, very helpful! Clear and simple.

retiredshitposter
Автор

The worst introduction I've ever seen

FirstLast-dkek