+ 1

del variable?

What is the use of del? spam=2 eggs=3 eggs=4 spam=5 print(eggs*spam) and spam=2 eggs=3 del spam eggs=4 spam=5 print(eggs*spam) produce the same thing

23rd Aug 2020, 10:48 PM
Sahiba Kaur
Sahiba Kaur - avatar
9 Antworten
+ 8
The course give you another chance to learn a new thing. I think it's quite useful for you learning in future. Hope this helpful! Programming is fun!
23rd Aug 2020, 11:00 PM
WenHao1223
WenHao1223 - avatar
+ 7
The del keyword is used to delete objects. In Python everything is an object, so the del keyword can also be used to delete variables, lists, or parts of a list etc. https://www.w3schools.com/python/ref_keyword_del.asp Rmb to tag the programming language you used next time. I suppose you are using python since you are learning python course now. Hope this is helpful! Programming is fun! 🤗😁
23rd Aug 2020, 10:57 PM
WenHao1223
WenHao1223 - avatar
23rd Aug 2020, 11:06 PM
Abhay
Abhay - avatar
+ 3
Thanks so much, everyone, that makes sense! I now understand why del is used and the real world aspects :) I just found out about this website yesterday and I am loving it! The class is so helpful and the lessons are really fun, and everyone who answers questions is very nice and helpful, so thanks!!
23rd Aug 2020, 11:16 PM
Sahiba Kaur
Sahiba Kaur - avatar
+ 2
Thanks! Yes, I am doing python :) I'll remember to tag next time, sorry about that! My question is why is it necessary to even have del, since in the example in the first post, it gives the same output?
23rd Aug 2020, 10:59 PM
Sahiba Kaur
Sahiba Kaur - avatar
+ 2
This is an example of how to use "del". Another use, a more practical use would be to delete sensitive data from being accessed. Take for example the getpass.getpass() function. While this function obfuscates the users password while being entered, the password can still be accessed again, it can be read, it can be used in other unintended ways. Therefore, the "del" command is useful here. After the password variable has been applied, the del command can be used to prevent any malicious intentions. These examples are used to get you thinking about practical application and use. The del command also frees up resources, so if you're having resource related issues, del could help here too.
23rd Aug 2020, 11:00 PM
Steven M
Steven M - avatar
+ 2
The object is dereferenced and the 2 latest values are used.. 4*5=20 😶
24th Aug 2020, 1:34 PM
Sanjay Kamath
Sanjay Kamath - avatar
0
The answer for del variables is 20
24th Aug 2020, 8:31 PM
Xync Step