Hi, 6, -1 or 0 are not bools (True or False): >>> 6 is True False >>> 0 is False False If you had to design a language and want to think about using numbers in a logical context you could do at least two things: 1) convert the number to bool, ie define a set of rules to assign to each number a logical value, or 2) don't convert and raise an error. In python, like in many other languages, option 1) has been chosen. The rules are roughly: when using a number in a logical context 0 is casted to False, and the other numbers are considered True. The "while" statement expects an expression that returns a logical value. Put both things together and I think you get your answer, if I well understood. Best
2014-05-20 10:25 GMT+02:00 Ian D <dux...@hotmail.com>: > I was reading a tutorial that had these examples in it: > > >>>> while False: > > print("False is the new True.") > > >>>> while 6: > > print("Which numbers are True?") > > > while -1: > > print("Which numbers are True?") > > > while 0: > > print("Which numbers are True?") > > > > Unfortunately the author never explained these statements. > > > I was wondering if the gist of a while statement could be explained in the > context of these examples. > > > e.g. while False: > > > means while True is False, which is never True because True is of course True > not False. > > > but while 6: > > > means..... err while 6 is True? and this is True because... err. > > > Anyway I am a bit lost with this. > > > Can anyone shed any light please? > > > Thanks. > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor