Friday, November 24, 2006

some interesting Python finds

as part of the plan to get my life back on track, i've been (re-)learning Python using How to Think Like a Computer Scientist. i've found some interesting things along the way, such as:
  • that you can use the modulo operator (%) with floating-point numbers, at least in Python. it works as you'd expect, including the floating-point inaccuracies. it's interesting that it still works with both arguments as floating-point numbers. just don't use the results in a place human life may depend on :D
  • that you can use the regular math syntax with Python. x <= y <= z is a boolean expression that returns true if x is less than or equal to y and y is less than or equal to z.
  • the int(), str() and similar functions actually return types when treated as a variable. so this: isinstance(myVar, int) and import types isinstance(myVar, types.IntType) are functionally equivalent. the reason i say it's interesting is because other functions return a function variable, not a type. i'm not quite sure that last statement makes sense, but pythonistas should get the idea. i'm using Python 2.4.4, so if these thingies don't work for a different, don't blame me :D

No comments: