# 第26組 **第26組組員: 110211025 黃巧瓈 110211015 吳玗苀 110251018 李佳臻 110251021 潘妘昕** ## **<font color="#9E25F6">2022年2月14日</font>** ### **Python Arithmetic Operators 算數運算子** > Arithmetic operators are used with numeric values to perform common mathematical operations: | 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 | ### **Python Assignment Operators 指派運算子** > Assignment operators are used to assign values to variables: | Operator | Example | Same As | 講述 | |:--------:|:--------:|:---------- |:------------- | | = | x = 2 | x = 2 | 把2指定給x | | += | x += 3 | x = x + 3 | 把x+3指定給x | | -= | x -= 3 | x = x - 3 | 把x-3指定給x | | *= | x *= 3 | x = x * 3 | 把x*3指定給x | | /= | x /= 3 | x = x / 3 | 把x/3指定給x | | %= | x %= 3 | x = x % 3 | 把x%3指定給x | | //= | x //= 3 | x = x // 3 | 把x//3指定給x | | **= | x **= 3 | x = x ** 3 | 把x**3指定給x | ```python= x=5 x-=1 print(x) # 4 ``` 課堂練習-計算BMI值:BMI = 體重 (kg) / 身高 (m^2^) (身高:165 體重:50 女) ```python x=50 y=1.65 print(x/y**2) #18.4 ``` ### **Python Comparison Operators 比較運算子** > Comparison operators are used to compare two values 用來比較兩個值: | 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 | ```python= x = 7 y = 6 print(x == y) #returns False because 7 is not equal to 6 ``` ```python= x = 3 y = 1 print(x <= y) #returns False because 3 is neither less than or equal to 1 ``` ### **Python Logical Operators 邏輯運算子** >Logical operators are used to combine conditional | Operator| Name |Example | | -------- | -------- | --- | | and | 且 | x < 5 and x < 10 | | or | 或 |x < 5 or x < 4| | not| 皆不滿足條件 |not(x < 5 and x < 10) | ### **Python Identity Operators 身份運算子** | Operator | 描述 | Example | |:-------- |:------------------------------------ |:---------- | | is | 如果兩個變量是同一個對象,則為True | x is y | | is not | 如果兩個變量不是同一個對象,則為True | x is not y |
{"metaMigratedAt":"2023-06-16T19:35:16.791Z","metaMigratedFrom":"Content","title":"第26組","breaks":true,"contributors":"[{\"id\":\"99e010f9-805a-41e2-bba0-203b4e9e7899\",\"add\":13179,\"del\":13181},{\"id\":\"fbc26178-6978-4ae2-a2c8-7c4580d9220e\",\"add\":3541,\"del\":1194},{\"id\":\"6f3c2727-a1fe-46ec-8a67-88648fdb47ad\",\"add\":746,\"del\":354}]"}
Expand menu