การดำเนินการทางคณิตศาสตร์ใน python สรุปจากโค้ดเลยได้ดังนี้
a=10
b=15
c=5.5
d=-125
print(a+b) #10+15
print(b-a) #15-10
print(a*c) #10x5.5
print(b/a) #15/10
print(b//a) #15//10 result only floor
print(b%a) #15%a modulo the remainder after division
print((-a)+b) #-10+15
print(abs(d)) #absolute a
print(a**b) #a^b or a exponent b
ลำดับการดำเนินการของตัวดำเนินการ order of operations
Parentheses หรือ ( )
Exponents หรือ **
Multiplication and Division หรือ * , / , // , %
Addition and Subtraction หรือ + , -
มีเทคนิคการจำง่ายๆคือ Please excuse my dear aunt Sally. แหล่งที่มาแอบอ้าง https://en.wikibooks.org/wiki/Python_Programming/Basic_Math
มีเทคนิคการจำง่ายๆคือ Please excuse my dear aunt Sally. แหล่งที่มาแอบอ้าง https://en.wikibooks.org/wiki/Python_Programming/Basic_Math
ไม่มีความคิดเห็น:
แสดงความคิดเห็น