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

Jasmine Epps
Jasmine Epps
279 Points

What is a variable? How would I add a line and where? and why should I use the del button?

What is a variable? How would I add a line and where? and why should I use the del button? If I'm adding a line, why would I delete it? and is it possible to delete lines of code? if so, how so? but, more than anything I really would like to know about naming variables, help?

delete.py
current_count = 14
planned = 5
upcoming_releases = 2
Jupil Yoon
Jupil Yoon
1,692 Points

variable is what's on the left side: variable current_count, planned, upcoming_releases

variable has a value assigned to each of them, current_count has variable of 14 and so on..

Task is to delete planned variable which is not needed anymore. It can simply be deleted by just deleting the line, but it's asking to use KEYWORD del to delete planned variable.

del planned

1 Answer

What a Variable is

The wording on the left is your variable, and the stuff on the right is the content that will be stored inside the variable.

# this is a variable
num1 = 1
num2 = 2

From that example, the integer or number 1 is stored inside the variable num1 and the integer 2 is stored inside the variable num2.

Since now both those values are stored inside the variables, I can add them together if I wish.

num1 + num2

# this will return the integer 3.

Deleting a variable

But using the del function, you can delete a variable.

For example: I now want to delete the num1 variable that I created previously. I can do it quite simply by using del.

del num1

# num1 is now deleted from the code.

If you need any more help, hit me up! Hope this helps!