hi everyone

ı am a new begıner .
why and when do we have to use "None"

for example if x. is None:
or at the definatıons

def lookfor(a, b=None): return a, b

why and where are we usıng None.whats the aım to use that

and my other questıon ıs when do we need to make list of lists

thanks alot for your answers


have a nıce year and day:)

None is used to signify the absence of a value, for instance it is returned from functions that don't explicitly return anything. Its truth value is false.

why and where are we usıng None.whats the aım to use that

Using None as a default value to a function is often useful to give different options. Here is a small example:

def zed(a, b=None):
    name = a.capitalize()
    if b: name = name + " " + str(b).capitalize()
    print name

With this example, you could pass just a first name, or both a first and a last name as two separate values. The more you code for end users the more you will understand this. When you don't know what kind of values you are going to get, it is useful to have a way to give optional values.

and my other questıon ıs when do we need to make list of lists

Easy. Write some bigger projects and you will soon find an example. More likely you will use dicts with lists as the values, or, if it all gets to much, use a database. But lists in Python are just such useful tools and easy to do thing with that you will find you keep coming back to them. More than lists of lists you will more likely find that you use lists that map through lists:

print "\n".join([a**2 for a in [4, 5, 30, 14]])

for example

Or, say a list of equipment, with each peice having it's own list of AC, slot to equip in, etc.
:D Just my $0.02 for games

This article has been dead for over six months. Start a new discussion instead.