# 0214 ## 一、運算子 ### 1.算術運算符 >| operator | name | example | >|:--------:|:--------------:|:-------:| >| + | addition | x+y | >| - | Subtraction | x - y | >| * | Multiplication | x * y | >| / | Division | x / y | >| % | Modulus | x % y | >| ** | Exponentiation | x ** y | >| // | Floor division | x // y | ### 2.賦值運算符 >| operator | example | same as | >| -------- | ------- | ------- | >| = | x = 5 | x = 5 | >| += | x += 3 | x = x + 3 | >| -= | x -= 3 | x = x - 3 | >| /= | x /= 3 | x = x / 3 | >| %= | x %= 3 | x %= 3 | >| //= | x //= 3 | x = x // 3 | >| **= | x **= 3 | x = x ** 3 | >| &= | x &= 3 | x = x & 3 | >| l= | x l= 3 | x = x l 3 | >| ^= | x ^= 3 | x = x ^ 3 | >| >>= | x >>= 3 | x = x >> 3 | >| <<= | x <<= 3 | x = x << 3 | ### 3.比較運算符 >| Operator |Name | Example | >| -------- | -------- | -------- | >| == | Equal | x == y | >| != | Not equal | x != y | >| > | Greater than | x > y | >| < | Less than | x < y | >| >= | Greater than or equal to | x >= y | >| <= | Less than or equal to | x <= y | ### 4.邏輯運算符 >| Operator |Description | Example | >| -------- | -------- | -------- | >| and | Returns True if both statements are true | x < 5 and x < 10 | >| or | Returns True if one of the statements is true | x < 5 or x < 4 | ## 上課筆記 print 輸出,input 輸入 > 9指定給x > x=9 > print(x) ### 1.加減 > x = 5 >y = 3 print(x + y) >x = 5 x += 3 print(x) > x = 5 y = 3 print(x - y) > x = 5 x -= 3 print(x) ### 2.乘除 > x = 5 y = 3 print(x * y) > x = 5 x *= 3 print(x) > x = 5 y = 3 print(x / y) > x = 5 x /= 3 print(x) ### 3.5/6的(餘數) % >x = 5 y = 6 print(x % y) > x = 5 x%=6 print(x) ### 4.數字**幾(次方) > x = 2 y = 5 print(x ** y) #same as 2*2*2*2*2 > x = 2 x **= 5 print(x) ### 5.15/2的整數捨去小數點 // (求商) > x = 15 y = 2 print(x // y) #the floor division // rounds the result down to the nearest whole number >x = 15 x//=2 print(x) ### 6.判別 > x = 5 print(x > 3 and x < 10) #returns True because 5 is greater than 3 AND 5 is less than 10
{"metaMigratedAt":"2023-06-16T22:03:43.076Z","metaMigratedFrom":"Content","title":"0214","breaks":true,"contributors":"[{\"id\":\"4dfebb48-62e3-4093-b22e-bde00bb0bc86\",\"add\":2462,\"del\":0}]"}
Expand menu