Math Module โมดูลคณิตศาสตร์
โมดูล math เป็น built-in module ของ Python ที่มีฟังก์ชันทางคณิตศาสตร์มากมาย เช่น รากที่สอง ตรีโกณมิติ ลอการิทึม และค่าคงที่ทางคณิตศาสตร์
การ Import
Section titled “การ Import”# Import ทั้งโมดูลimport math
print(f"Pi = {math.pi}")print(f"E = {math.e}")print(f"sqrt(16) = {math.sqrt(16)}")
# Import เฉพาะฟังก์ชันที่ต้องการfrom math import sqrt, pi, pow
print(f"\nPi = {pi}")print(f"sqrt(25) = {sqrt(25)}")print(f"pow(2, 3) = {pow(2, 3)}")เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google