Monday, June 15, 2009

Python basics : math functions, main funct

Math functions
#Unfortunately, you need to import math, but python has a nice library of math functions



import math
math.pow(2,3)
math.cos(math.pi/2) #<-- radians!
math.pi
math.sqrt(4)



Main function

#Making a main function in Python is a little tricky. Here is an example:



def main(*args):
if len(args) < 4:
return

print "main : args[0] ", args[0], " args[1]", args[1]
print "(main) : args[1] ", args[2]
print "(main) : args[3] ", args[3]

if __name__ == "__main__":


No comments: