In-place operation เปลี่ยนค่าตรงในตัวแปรโดยไม่สร้าง copy ใช้โมดูล operator
| ฟังก์ชัน | เทียบเท่า | คำอธิบาย |
|---|---|---|
iadd(a,b) | a += b | บวกและกำหนด |
isub(a,b) | a -= b | ลบและกำหนด |
imul(a,b) | a *= b | คูณและกำหนด |
itruediv(a,b) | a /= b | หารและกำหนด |
imod(a,b) | a %= b | mod และกำหนด |
iconcat(a,b) | a + b | concat sequence |
ตัวอย่าง
import operator
print(operator.iadd(1,3)) # 4
print(operator.isub(8,6)) # 2
print(operator.imul(8,6)) # 48
print(operator.itruediv(54,6)) # 9.0
print(operator.imod(10,5)) # 0
print(operator.iconcat("jupyter", " notebook")) # jupyter notebook