Latest web development tutorials

cos Python3 () ฟังก์ชัน

Python3 ดิจิตอล Python3 ดิจิตอล


ลักษณะ

cos () ผลตอบแทนโคไซน์ของ x เรเดียน


ไวยากรณ์

ต่อไปนี้เป็นไวยากรณ์ cos () วิธีการ:

import math

math.cos(x)

หมายเหตุ: cos () ไม่สามารถเข้าถึงได้โดยตรงคุณจำเป็นต้องนำเข้าโมดูลคณิตศาสตร์และจากนั้นเรียกวิธีการจากวัตถุคงคณิตศาสตร์


พารามิเตอร์

  • X - ค่า

ราคาย้อนกลับ

ผลตอบแทนที่โคไซน์ของ x เรเดียนระหว่าง -1 ถึง 1


ตัวอย่าง

ต่อไปนี้จะแสดงให้เห็นตัวอย่างของการใช้ cos () method:

#!/usr/bin/python3
import math

print ("cos(3) : ",  math.cos(3))
print ("cos(-3) : ",  math.cos(-3))
print ("cos(0) : ",  math.cos(0))
print ("cos(math.pi) : ",  math.cos(math.pi))
print ("cos(2*math.pi) : ",  math.cos(2*math.pi))

หลังจากทำงานเอาท์พุทตัวอย่างข้างต้นคือ

cos(3) :  -0.9899924966004454
cos(-3) :  -0.9899924966004454
cos(0) :  1.0
cos(math.pi) :  -1.0
cos(2*math.pi) :  1.0

Python3 ดิจิตอล Python3 ดิจิตอล