3

I am new to coding. I saw some code where variable = None, what does it mean? I can't find an answer anywhere online.

Thanks in advance!

verkter
  • 758
  • 4
  • 15
  • 29

2 Answers2

5

It sets a variable named variable to None (Python's version of a null/nonetype object).

See a demonstration below:

>>> variable = None
>>> type(variable)
<type 'NoneType'>
>>>

I really think you should read one of the many Python tutorials out there since this is a fundamental language concept. Here are some I found useful:

http://docs.python.org/2/tutorial/

http://www.tutorialspoint.com/python/python_overview.htm

  • Thanks for pointing me towards tutorials, but what is the difference between setting variable to 0 versus setting it to None? – verkter Nov 29 '13 at 21:13
  • @verkter - It depends on the program. You are right in saying that, in a lot of areas, the two can be used interchangeably (since each evaluate to `False`). However, there are some instances when you need a nonetype/null object and `0` will not suffice. An example is with the [`filter`](http://docs.python.org/2.7/library/functions.html#filter) built-in. –  Nov 29 '13 at 21:18
0

It assigns the value None to the variable variable. I recommend you read the tutorial; it will answer this question and many more.

user2357112
  • 260,549
  • 28
  • 431
  • 505