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

how to delete a variable in python

how do i delete a variable in python?

i wrote del 'planned'

but it comes back with an error each time

delete.py
current_count = 14
planned = 5
upcoming_releases = 2

Hey @Zachary Wheeler, There are two easy ways to delete a variable in Python that i can think of.

1- Use a key word del. There is no need to use quotes with keyword del.

del current_count 

2- Set a variable to None. None is similar to null in other languages.

current_count = None

Thank you.

2 Answers

Did you actually put planned in quotes? That would definitely throw an error because in this example planned is a variable. You would need to type:

del planned

Have tried myself but it does not work. It keeps saying it's an error del planned