Python Quick Tip: The Difference Between "==" and "is" (Equality vs Identity)

  Рет қаралды 122,206

Corey Schafer

Corey Schafer

Күн бұрын

Пікірлер: 213
@pepehimovic3135
@pepehimovic3135 5 жыл бұрын
⚽ = "football" 🏈 = "football" ⚽ == 🏈 >>> True ⚽ is 🏈 >>> False
@ghostriley22
@ghostriley22 5 жыл бұрын
football != handegg
@coreyms
@coreyms 5 жыл бұрын
Haha. That’s great
@vaguebrownfox
@vaguebrownfox 5 жыл бұрын
neat
@ViratKohli-jj3wj
@ViratKohli-jj3wj 5 жыл бұрын
Thats great way of explanation, I appreciate it
@angjohnsyin9517
@angjohnsyin9517 5 жыл бұрын
Thanks zlatan
@Remls
@Remls 5 жыл бұрын
'coke' == 'pepsi' *_BLASPHEMY!_*
@Xartab
@Xartab 5 жыл бұрын
I had no idea lists would behave like that, that's really important to keep in mind when assigning variables!
@shreyashkashyap
@shreyashkashyap 3 жыл бұрын
Extremely well explained! It was a bit confusing in the pepsi example but the programming example made it all clear.
@scarletdcruz7843
@scarletdcruz7843 5 жыл бұрын
Are you writing a book? Cause I'd buy it.
@rsrazorfen
@rsrazorfen 5 жыл бұрын
Hi Corey, I've been watching many of your videos (especially the flask-tutorial) and just wanted to thank you. Those videos basically got me started with python and helped me not only for my personal coding but also for my job. You're doing an amazing work - keep it up man, much love from Germany!
@umaraftab6073
@umaraftab6073 5 жыл бұрын
I just watched your video on Unit Testing and wished to have you upload the next one. And, then here it is. :)
@TexasGunDude
@TexasGunDude 5 жыл бұрын
You just got a new Patreon supporter.
@coreyms
@coreyms 5 жыл бұрын
Thanks!!
@Gaspar.Albertengo
@Gaspar.Albertengo 5 жыл бұрын
Excellent. Would be nice to see how "is" interacts with "not", "in", ect.
@nythepegasus
@nythepegasus 4 жыл бұрын
I know this is a very old comment, but you cannot use is with in, it throws a SyntaxError. “is not” gives a SyntaxWarning asking if you meant “!=“
@lukebircharchive3833
@lukebircharchive3833 4 жыл бұрын
@@nythepegasus The syntax warning is because you probably should've used "!=" or not "==" in that case instead of "is not". If you type in "2 is 3", it would probably show you the same warning.
@leondaz
@leondaz 5 жыл бұрын
I love you man, really thanks, I came to the newest video you posted just to thank you for everything, I hope you see this
@karimkohel3240
@karimkohel3240 5 жыл бұрын
this is the best type of content please keep educating us like that
@Ghasakable
@Ghasakable 5 жыл бұрын
Man we missed you so much!!, I
@zakariyaabubakar6298
@zakariyaabubakar6298 5 жыл бұрын
Thanks Corey. Your a gifted teacher
@PandhuW
@PandhuW 9 ай бұрын
I like your explanation. I also like your pandas tutorial video. Btw, I saw this in a book a = [1, 2, 3] c = list(a) a == c >>> True a is c >>> False
@scotttct
@scotttct 5 жыл бұрын
I am taking a course on Python and this was very helpful to see how and why the == and is comparisons are used in code. Thanks!
@nehat786
@nehat786 5 жыл бұрын
thank god you came back
@UrstrulyPrathap
@UrstrulyPrathap 5 жыл бұрын
Thank you so much sir..... finally I got Python developer job ❤️ ..only because of your tutorials❤️
@nicoTheGreatswordUser
@nicoTheGreatswordUser 5 жыл бұрын
How did u start in python
@coreyms
@coreyms 5 жыл бұрын
Congrats!
@aashayamballi
@aashayamballi 5 жыл бұрын
Thanks Corey 😊
@ulfgj
@ulfgj 3 жыл бұрын
@3:46 - now how did u space out that list so nicely? shortcut?
@LuisSanchezLouieLouie
@LuisSanchezLouieLouie 4 жыл бұрын
Great example man. thanks
@NomadLovesUs
@NomadLovesUs Жыл бұрын
Clear and concise, thank you!
@SeaTaj
@SeaTaj 3 жыл бұрын
Thank you. Great content as usual. Is it weird that I'm binging your content?
@davidm.johnston8994
@davidm.johnston8994 5 жыл бұрын
Thank you for this video Corey!
@blueexorcist4300
@blueexorcist4300 5 жыл бұрын
what happens if you use the is on two primitives?
@changanzhang3124
@changanzhang3124 5 жыл бұрын
Corey you're awesome! How do you actually learn all these....and explain them in such a simple manner...and make these videos open source. Thanks!
@nathantum8463
@nathantum8463 5 жыл бұрын
I think he should make a video on how he learns all the new stuff.
@fredwooten14
@fredwooten14 5 жыл бұрын
Thanks Corey, Great video!
@cati4142
@cati4142 5 жыл бұрын
I really love your work! Thank you so much for your videos! Will you publish something about statistics with python? hypothese testing, linear regression or something? Would be sooo great
@rounakghosh6213
@rounakghosh6213 Жыл бұрын
Awesome, thanks for the clear explanation..
@oltlatifi4870
@oltlatifi4870 5 жыл бұрын
Thank you for what you're doing
@rodwanbakkar2512
@rodwanbakkar2512 4 жыл бұрын
I like your videos before watching them
@aikimark1955
@aikimark1955 5 жыл бұрын
I wish you had included a "Type() is" example as well as the .copy() method for your second list
@glorytoarstotzka330
@glorytoarstotzka330 5 жыл бұрын
4:15 question : could you also do "print(l1 == l2)" instead of "if l1 == l2: print(True) else: print(False)" ? . Edit: I see that at the end of the video you've done this , so my question has been answered
@coreyms
@coreyms 5 жыл бұрын
Yes. I just did it with the conditional at first so that it was more clear what was going on.
@lethanhtu125
@lethanhtu125 5 жыл бұрын
Your video really easy to understand
@leondaz
@leondaz 5 жыл бұрын
I understand them perfectly because I made a project using them, but I still like if corey explains them, cause 100% I'll learn something new
@rainbowskeppy5292
@rainbowskeppy5292 3 жыл бұрын
3:55 you could just write print(l1 == l2)
@davidcarter8932
@davidcarter8932 4 жыл бұрын
Your videos are exceptional. I enjoy them all. In this one it would help to expand a little on when to use "is" or ==. Linter seems to want me to use "is" in logical comparisons, but doesn't complain about == in other comparisons. So, should we use "value is True" and "x == y"? "Value is True" seems to work, but I don't trust it based upon your description about having identical memory locations. Are True and False assigned fixed memory locations and logical variables assigned one of those two memory locations? Since I don't know the answer, I am inclined to always use == which may not be pretty, but it works. What do you think?
@ulfgj
@ulfgj 5 жыл бұрын
corey, whats the color theme for sublime you are using here? it's so smoooth.
@coreyms
@coreyms 5 жыл бұрын
Predawn
@rajath1964
@rajath1964 5 жыл бұрын
@@coreyms how to comment multiple lines at once using '#' (single line comment), i see many youtubers do that but just cant figure it out. like what i mean is : use # to comment multiple selected /highlighted lines with single click
@Bread-vk8fl
@Bread-vk8fl 3 жыл бұрын
How to comment everything like he did at 5:59?
@arar4454
@arar4454 5 жыл бұрын
Can you make some videos to : How i make exponential fits and gaussian fits
@EnglishRain
@EnglishRain Жыл бұрын
You are so fantastic i live you and miss you thank you so much for your amazing content!!
@krishnachaitanya1078
@krishnachaitanya1078 5 жыл бұрын
Thank you corey
@khireddinebelkhiri725
@khireddinebelkhiri725 5 жыл бұрын
do you know bro u are great thank you from algeria
@thinktech2936
@thinktech2936 Жыл бұрын
Very well explained
@adityaprasaddhal2462
@adityaprasaddhal2462 5 жыл бұрын
Thanks for knowledge
@yoyolubi
@yoyolubi 7 ай бұрын
Let me se if i got it right... so basicaly when you use l2 = l1 in Python is the same thing as you use int* l2 = l1 to point to the l1 array in C, both lists (or arrays) end up refering to the same memory address? But when i use l1, l2 = 100, 100 print(l1 is l2) It returns true, so why? I mean... i didnt use l1 = l2 although they have the same value... Is it because both are the same instance of the integer class in Python, and by that refers to the same object when l1 and l2 variables recives their values?
@MJFAN666
@MJFAN666 5 жыл бұрын
That's weird.. So what if I say l2=l1 and modify l2? Will it also change l1?? What if I wanted to make a copy of the var without messing with mem location?
@jinyang4796
@jinyang4796 4 жыл бұрын
== checks for equality is checks for identity (i.e. are the objects from the same memory address?) Values can be considered equal without being the same object in memory.
@khalidhassani6173
@khalidhassani6173 5 жыл бұрын
KZbin has got a talent is Schafer
@hamidsk2573
@hamidsk2573 5 жыл бұрын
dear Corey can you made python tutorial for the advance programming feature in python like multitasking , multithreading and async task
@robot341
@robot341 5 жыл бұрын
This is Important topic, Good !!
@souvikghosh6966
@souvikghosh6966 5 жыл бұрын
If the names to the two persons are the same, then we call they are '==' to each other. If they look like exactly the same like twins then we call they are identical, which means they are 'is' to other. Nice!!!
@legend7890
@legend7890 4 жыл бұрын
really good explanation
@tinman222
@tinman222 5 жыл бұрын
Hey Corey , i am using ckeditor in a django blog app hosted on digital ocean , and using digital ocean spaces for serving static files which uses amazon s3, but when it is not working properly can u plz make a video on it, i am debugging for atleast 10 days ckeditor uploader not working and even when it says paste the url it also not working, plz plz plz help me plz its very important and urgent bcoz my app is already on server
@ericdrumond_ancap
@ericdrumond_ancap 5 жыл бұрын
Hey man, I am from Brazil and I like a lot your videos. Do you have plans to make a Kivy Tutorials??? Thank you for the amazing videos.
@GK-lf1ll
@GK-lf1ll 5 жыл бұрын
Why do we have two variable names for same memory location? Where can we apply in programming?
@s1n7ax
@s1n7ax 5 жыл бұрын
If you have a object list, and you want to remove a given object from the list, you can use 'is' i guess. Not a python programmer but most of the languages are using 'is' concept by default so this is one use case.
@franciscorossi5633
@franciscorossi5633 4 жыл бұрын
Could anybody tell me which program or text editor is he using to run Python in this video? Thanks
@linuxrant
@linuxrant Жыл бұрын
wonderful video!
@mauricioyaman570
@mauricioyaman570 5 жыл бұрын
excelent explanation
@Yashparwal1
@Yashparwal1 2 жыл бұрын
thanks for the explanation
@samytamim2603
@samytamim2603 Жыл бұрын
can we use is keyword with Primitive Values ?
@poke_champ
@poke_champ 5 жыл бұрын
Corey Schafer uploads *[EVERYBODY LIKE THAT]*
@rubemjr9623
@rubemjr9623 5 жыл бұрын
So is the is keyword equivalent to comparing C pointers?
@Miyota_9015
@Miyota_9015 5 жыл бұрын
Thanks bro, any chance of you recording a series on Flutter in the future? that would be amazing!
@tyt00341
@tyt00341 5 жыл бұрын
Thanks u teach well may I check which python IDLE are u using thanks
@lelgenio
@lelgenio 5 жыл бұрын
I think he uses Sublime text Also, IDLE is the name of the simple python IDE I would recommend you trying Thonny if you are just starting
@ihalil95
@ihalil95 5 жыл бұрын
Amazing video as always. My question is x = 2 y = 2 if x is y: print(True) x and y are different. but their id(x) and id(y) are the same. Why? Also when make y = 2.0 float its id changes.
@coreyms
@coreyms 5 жыл бұрын
That’s because some common values are immediately stored in memory when Python is first run for efficiency reasons. So sometimes you get behavior like this. But I wouldn’t rely on using “is” in that way in your programs because it won’t always be true.
@CT7ALW
@CT7ALW 5 жыл бұрын
Check my answer to Avinash Pandey ( &lc=UgwEAvkuTKLuEe27Kfh4AaABAg.8yIgY8IB_8f8yIrgMw5R6u )
@ginopornasdoro9183
@ginopornasdoro9183 5 жыл бұрын
do you have laravel tutorial?
@haroldaaron2098
@haroldaaron2098 4 жыл бұрын
Great videos about python, please make a video about comparison of Pass by value,reference and Pass by object reference in python, Hope to see more videos also in advance python
@tinman222
@tinman222 5 жыл бұрын
Or can u make a video on how to implent a good wsywig editor which has file uploading and accesing functionality in in django app on front and also on admin panel , in text area
@ricardoseung1785
@ricardoseung1785 4 жыл бұрын
Is the command "is" the same as command "="? thank you!
@tiagu8085
@tiagu8085 4 жыл бұрын
No. '=' is assignment
@RichellyItalo
@RichellyItalo 5 жыл бұрын
Please, what's your font family?
@coreyms
@coreyms 5 жыл бұрын
Source Code Pro
@RichellyItalo
@RichellyItalo 5 жыл бұрын
@@coreyms thanks. One more thing. And the color scheme?
@coreyms
@coreyms 5 жыл бұрын
Richelly Italo Predawn. I have a video on how I set up my Sublime Text if you want to see the full setup.
@RichellyItalo
@RichellyItalo 5 жыл бұрын
@@coreyms Thanks man!!! I'm watching now.
@TeguhGunawan
@TeguhGunawan 5 жыл бұрын
Thanks 👍
@maievmaiev8327
@maievmaiev8327 5 жыл бұрын
how can i copy l1 in another list named l2, and when changing l2 it wont affect l1, cause by copiying with =, the changes done on l1 will accure on l2
@coreyms
@coreyms 5 жыл бұрын
Hey there. Great question. Instead of giving all the different options in a long comment, I think this StackOverflow answer does a great job of explaining your different options: stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list
@dmitryvlasov931
@dmitryvlasov931 5 жыл бұрын
l2=l1.copy()
@maievmaiev8327
@maievmaiev8327 5 жыл бұрын
@@coreyms thank u
@maievmaiev8327
@maievmaiev8327 5 жыл бұрын
thank u!
@balzerno1
@balzerno1 5 жыл бұрын
Its funny how i was looking at the exact same thing just before clicking on this video haha
@AbdurRahman-iy7nd
@AbdurRahman-iy7nd 4 жыл бұрын
Thanks for your definition. I got the point. But the example with pepsi is not so relevant.
@gfddgitgud3848
@gfddgitgud3848 2 жыл бұрын
Thank you Thank you Thank you !!!
@akansh_26
@akansh_26 4 жыл бұрын
I was writing a program which had a line as ------- if i != True: --------- here my idle asked to change it into -------- if i is not True ---------- why this happened? and what is the difference?
@pushpajitbiswas3752
@pushpajitbiswas3752 5 жыл бұрын
Good explanation, can you make a video over pandas, numpy, opencv any one of these?
@aggieaggie3946
@aggieaggie3946 5 жыл бұрын
hey Corey, thanks so much for the tutorials, they are really good but would you do a tutorial on how to all some one comment on your posts in your blog?thank you, i will really appreciate
@umaraftab6073
@umaraftab6073 5 жыл бұрын
Hey Corey, can you please make a short video explaining '_' and '__' used in variable declaration in Python? Thanks
@FixDaily
@FixDaily 3 жыл бұрын
That has to do with Private ( _ _ ) or Protect ( _ ) properties on Classes.
@coreycarter5668
@coreycarter5668 5 жыл бұрын
Even though I already understood this concept.....just going to watch the video because well-he’s amazing!
@geoClexE
@geoClexE 3 жыл бұрын
thank you so much !!!
@ranjeet1449
@ranjeet1449 5 жыл бұрын
So you switched back to sublime?
@coreyms
@coreyms 5 жыл бұрын
I use Sublime Text for my tutorials since it's pretty minimalist. I still also use VSCode for my day-to-day coding.
@ranjeet1449
@ranjeet1449 5 жыл бұрын
@@coreyms I started using atom its not bad, I'm liking it more than I thought I would.
@rajath1964
@rajath1964 5 жыл бұрын
@@coreyms name = "tony" name1 = "tony" print(id(name)) print(id(name1)) if name is name1: print(True) else: print(False) ******************************* the above code returns same memory reference and True. i think you specifically explained for lists
@needsomehike
@needsomehike 5 жыл бұрын
what text editor are you using in these videos? (does anybody know?)
@andreamagista6742
@andreamagista6742 5 жыл бұрын
Sublime text
@needsomehike
@needsomehike 5 жыл бұрын
@@andreamagista6742 thank you!!
@vkrs3315
@vkrs3315 2 жыл бұрын
Thank you so much
@mohsam3868
@mohsam3868 5 жыл бұрын
d=[0.25,0.10,0.50] def coin(num): for i in d: if num%i == 0: print(i) coin(1.25) coin(2.2) '''why the reminder in this case is not equal zero '''
@daniloreboucas5888
@daniloreboucas5888 5 жыл бұрын
2.2 % 0.1 returns a number very close to 0 instead idk why but on my console it is returning 5.5e-17 instead
@daniloreboucas5888
@daniloreboucas5888 5 жыл бұрын
I think when performing this division python uses very close approximation of the numbers instead of the actual values
@rajm5349
@rajm5349 2 жыл бұрын
WHAT are suites
@tulsivanol
@tulsivanol 5 жыл бұрын
Hello sir, Can u make a tutorial on numpy and pandas?
@Anjinink
@Anjinink 5 жыл бұрын
Hey, and how to use this 'is' ? common scenario.
@delapuenteignacio
@delapuenteignacio 5 жыл бұрын
Most commonly when you assign a True, False, None, etc to a variable, when you want to check for that is common practice to use it. So for example if I define x = False (some code that might change x to True) Here if I want to check if x is still False, I would say: if x is False: (more code) rather than if x == False: (code)
@0Navin0
@0Navin0 2 жыл бұрын
Thank you.
@aymaneboukrouh
@aymaneboukrouh 5 жыл бұрын
Can you make a tutorial on PyCharm ?
@ldizai
@ldizai 5 жыл бұрын
Hi Corey, thanks for all teh vids! Could you do one on how to check if the person is a subscription member or not in Python-Flask. I've learned everything in your Flask Blog app. So after that is done, how to set up members account for premium features via payment.
@desmondade
@desmondade 5 жыл бұрын
You can basically have a field in your user model name is_subscriber which is a bolean and set this value to true when a user subscribes in the payments route or you have a OneToOneField to add this extra info
@ldizai
@ldizai 5 жыл бұрын
Straight Emirati thanks!! I’ll test it out
@desmondade
@desmondade 5 жыл бұрын
@@ldizai yeah just try it out any problem I will be glad to help
@leemoore8154
@leemoore8154 4 жыл бұрын
This doesn't seem to work with integer values. a = 5 b = 10 - 5 print(a is b) ----- True If you change it to b = 10/2 to get a float, then it prints False, but if they're both integers with the same value, they seem to be stored in the same place in memory.
@benx5781
@benx5781 5 жыл бұрын
🏀=ball 🎾=ball 🏀=🎾 if 🏀==🎾: print("🏀==🎾") if 🏀 is 🎾: print("🏀 is 🎾") Here output will be: 🏀==🎾 🏀 is 🎾
@ember9361
@ember9361 Жыл бұрын
it did! thank you :)
@G_a_n_d_u
@G_a_n_d_u 3 жыл бұрын
Corey Schafer ! = others programmer❤️
@andrewluo6088
@andrewluo6088 5 жыл бұрын
you are the best teacher
@muhtadilaskar7650
@muhtadilaskar7650 5 жыл бұрын
You are awesome
@kamransiddique5731
@kamransiddique5731 5 жыл бұрын
Can you upload some videos on machine learning
@delapuenteignacio
@delapuenteignacio 5 жыл бұрын
One thing that might be worth adding is that if I define two integers rather than lists, then they both get stored in the same memory location. i.e. x = 3 y = 3 "x is y" outputsTrue. This won't happen with strings unless its just one word. So if x = 'a string' y = 'a string' "x is y" outputs False but if x = 'justoneword' y = 'justoneword' "x is y" outputs True. Go figure...
@rajath1964
@rajath1964 5 жыл бұрын
same holds good for string also, name = "tony" name1 = "tony" print(id(name)) print(id(name1)) if name is name1: print(True) else: print(False) ********************************* the above code returns same memory reference and True. i think he was specifically describing for lists
@scifregizmoguy
@scifregizmoguy 5 жыл бұрын
# An `is` expression: A is B # Will evaluate to a boolean. # An equivalent expression: id(A) == id(B)
@AjayJain-ef2mz
@AjayJain-ef2mz 4 жыл бұрын
what about id(A) is id(B)?
@sainco3036
@sainco3036 5 жыл бұрын
thanks.
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 455 М.
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
Avoid These BAD Practices in Python OOP
24:42
ArjanCodes
Рет қаралды 84 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 261 М.
How I Would Learn Python FAST (if I could start over)
12:19
Thu Vu data analytics
Рет қаралды 724 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 911 М.
HashMaps & Dictionaries, Explained Simply
22:44
Nic Barker
Рет қаралды 12 М.
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 67 М.