Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types Del

gordon kilgore
gordon kilgore
128 Points

i am lost! "Bummer!" ? delete the `planned` variable with the `del` keyword, yes

i am lost! "Bummer!" ? delete the planned variable with the del keyword, yes

delete.py
current_count = 14
planned = 5
upcoming_releases = del
don't delete the line
del favorate number
del (favorate_number)

del favorate_number 
no
del favorate_fruit
del (favorate_fruit)
del favorate_fruit

The challenge is asking to delete the variable planned using del. so, you just need to do this del planned.

1 Answer

Jeffrey James
Jeffrey James
2,636 Points

You can call "del variable" on any variable. Look at it with a clear head. Here's an example. Sometimes, rather than deleting something, you may also set it equal to None. However, None still has a space in memory and contains properties. The dir(some_variable) method exposes properties and methods of a variable, if you're not 100% clear on what it does.

In [6]: planned = 'the event we have'

In [7]: print(planned)
the event we have

In [8]: del planned

In [9]: print(planned)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-ff12f57317d2> in <module>()
----> 1 print(planned)

NameError: name 'planned' is not defined

In [10]: planned = 'the event we have'

In [11]: planned = None

In [12]: print(planned)
None

In [13]: dir(planned)
Out[14]: 
['__bool__',
 '__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__']