Mutability revisited - Python 3 Programming Tutorial p.8

preview_player
Показать описание
In this part, we're going to revisit the topic of mutable and immutable objects. This concept is masked pretty well in Python, which, like dynamic typing, can be great... or not. It can really bite you one day if you don't have a good understanding of how it works, so let's talk about it.

#python #programming #tutorial

quiz:

x = 1
def test():
x = 2
test()
print(x)

x = 1
def test():
global x
x = 2
test()
print(x)

x = [1]
def test():
x = [2]
test()
print(x)

x = [1]
def test():
global x
x = [2]
test()
print(x)

x = [1]
def test():
x[0] = 2
test()
print(x)
Рекомендации по теме
Комментарии
Автор

One piece of advice I can tell you guys that you have helped me out a lot. Don't just watch the tutorial and expect to learn everything about it. Take notes, write the program yourself, and try to understand every line of code. Also, don't be scared to break and rearrange the code as well for deeper understanding.

alexpedraza
Автор

I watched lots of tutorials in the big named websites and I paid a lot for those courses, I can absolutely say you are a gifted teacher and I love the way that you explain every thing in an easy way. You are the best and smartest teacher and thanks a lot for your amazing videos.

nanakiany
Автор

sentdex  I particularly loved this tutorial, partly because it was longer but mostly because of the way you took the time to outline and exhibit a common but tricky to grasp topic. Thanks again for all your hard work and dedication to helping those that need it.
Cheers!

lank_asif
Автор

please dont forget to forget topics like __init__, self, __main__ it is so confusing

usabnd
Автор

I got really confused when you did the whole game_map thing super quick, and said this is how id write everything .. super important. but you didnt explain wtf you just did lol. I found the same thing in your last video.. When if statements came out of no where.. unexplained. Help please

Naxxy
Автор

good stuff mate, i just started learning python like 2 days ago (coming from ADF/android development background ) and your videos are just different and more exciting to watch and learn from than other sources, i just want u to know this is the best tutorials ive seen on youtube, i usually check youtube for the topics i wanna learn and find nothing that much valuable and get back to learning from the good old docs, but this is actually entertaining and informative at the same time, thank you so much for your work <3 keep em coming.

TheSaver
Автор

Love your videos dude, not sure why people complain about premiere. Think some people just have nothing to do but complain and cry.
You are one of the few youtubers that don't flood my screen with ads. So having to wait and extra day to watch your videos is worth it.

People are just so ungrateful for the free knowledge that you provide. I bet you these are the same people that use ad block for youtube ads on other channels.

hawkeyezar
Автор

I love how you have a different mug for every video

Smokeybear
Автор

Great tutorial. Took me 90 minutes to work through it and understand what's happening. That said, it's making sense. Thank you.

johndunn
Автор

When you explain that the string "I want to play a game" is immutable, and that the print(game) within the function definition results in "A game". Is what's happening here related to 'scope'? It's a term I was introduced to while programming in C++. Basically, the scope of the function determines the control of only the variables within that function. They can't be changed from outside the function, and the function can't change variables outside of itself, due to the effects of it's scope. Is that why you call the "I want to play a game" string immutable? Or is it a separate concept?

ConorFenlon
Автор

This simple quiz made it so much easier to understand the concept of immutability. Thanks

jagroopdeol
Автор

I have really liked this beginner series until this video. Once you started talking about "immutable", which is obviously very important, you went WAY faster and it was much harder to keep up. Super frustrating. Had to watch it 4 times to start to get it.

autonomouspi
Автор

Man I love your videos. I learned a lot from your series on machine learning using python. Now I watch everything you share on YouTube. I love your way of teaching us. Best

wasimshoman
Автор

sentdex....i owe a lot to you. A CEO once linked your channel on quora and I followed your channel to learn. I applied as an intern to the CEO's startup and got accepted. I even transitioned into a well paying full time position too. Thanks man and I hope you make great progress through this channel and help many others.

prasanth_m
Автор

This is why python REALLY needs a declaring variable sytanx.
The problem of "why isn't this being changed" is because python thinks you are declaring a new variable inside the function since by default it doesn't access global variables. Of course you can't declare a variable when using the [ ] operator, so it will try to find a global variable for that.

With a keyword like "let" it would be crystal clear what is being created or accessed, and the interpreter could yell at you if you try to access a global variable without saying it, instead of silently creating a new one

cicciobombo
Автор

Omfg, you do a fucking GREAT job for free and people still complaining, holy shit. I mean, I'm a patient person, but even Buddha would get pissed off with this kids. You do an amazing job dude, I will always comeback here!

newtincarai
Автор

I wish I watched this video this weekend! I have been sweating over a global variable for days! Finally got it worked! Thanks for sharing.

usabnd
Автор

Hi, sorry to say but your explanation of accessing and changing outside variables inside functions is not correct. You are mixing object mutability and variable scope. This is misleading.

brotherlui
Автор

While watching this video I was keep asking myself why do I never counter such problem, but then in the end you mentioned the methodology that you've been using for seven years, which exactly what I always do. I am lucky

kameraderz
Автор

dammm this one blended my mind i have to take it easy and come back

OvidianHEX_
join shbcf.ru