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

Zachary Wheeler
Zachary Wheeler
1,157 Points

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
Kirill Babkin
Kirill Babkin
19,940 Points

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

David Bath
David Bath
25,940 Points

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
kevin mwangi
kevin mwangi
1,101 Points

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