Python中的三角函數位於math模塊內。
引入模塊:
1 import math
輸出pi
1 import math 2 print(math.pi)
得:3.141592653589793
math模塊內還有sin、cos、tan之類的函數,與C#的用法一致。
但有一點要注意的是:
1 import math 2 print(math.tan(math.pi/4))
將會輸出:0.9999999999999999
而C#中:
1 Console.WriteLine(Math.Tan(Math.PI/4));
將輸出1