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 Collections (2016, retired 2019) Dungeon Game Dungeon Entrance

Setting Variables to None

Why are monster, door, and player initially set to None?

3 Answers

It is useful for defining variables "without actually giving them a value". If you need to define a variable but you don't need to set it to a value you can use None as the assignment value. In JavaScript it would look like this:

var moster;
var door;
var player;

In Python it would like this:

moster = None
door = None
player = None

This will create the variables, but they won't have a starting value.

Just keep learning Python and you'll see this is helpful in some cases.

I hope this helps. ~Alex

You can set a variable to None it python to initialize it, so that you can reference the variable later in the program. Hope this helps.

Thanks for the responses!

Can you give either of us (either Khaled or I) a Best Answer so that this question appears as answered in the Community? Thank you. ~Alex