ACCEPTED: PEP 285
David Eppstein
eppstein at ics.uci.edu
Wed Apr 3 21:11:54 EST 2002
More information about the Python-list mailing list
Wed Apr 3 21:11:54 EST 2002
- Previous message (by thread): ACCEPTED: PEP 285
- Next message (by thread): ACCEPTED: PEP 285
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <3CABB156.1010401 at nospam.attbi.com>, djw <dwelch91 at nospam.attbi.com> wrote: > Pardon my ignorance (I've only been working with Python for a short > while), but I don't understand why an idiom like: > > if x == True: > > would be/should be an error (or warning initially). Because it will give the wrong result when x is a list, or other type of object that is not a bool but can be used as a truth value. > I see C/C++ code > like this all the time: > > bool x; > x = Foo(Bar); > if (x==true) > {... C/C++ forces its variables to have declared types, so you can be sure that x is a bool -- if it is not true, it must be false. In Python, you have no guarantees about the type of x, and should be prepared to handle any type of value that might make sense in the context. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
- Previous message (by thread): ACCEPTED: PEP 285
- Next message (by thread): ACCEPTED: PEP 285
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list