while var, but var ==16 != true

maestro notnorwegian at yahoo.se
Sun Jul 13 23:03:38 EDT 2008


why does this work?  "while p" = "while p != 0" ? 1 is True and 0 is
false in python but other numbers have no boolean value so why doesnt
it abort.



>>> p=16
>>> p
16
>>> while p:
	print p
	p -= 1


16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
>>>


i can also do:

>>> k=[]
>>> while k:
	k.pop()


>>> k=[1,2,3]
>>> while k:
	k.pop()


3
2
1
>>>


so obv while var means while not empty or why not zero but it isnt
something youd guess unless youd beeen shown it.



More information about the Python-list mailing list