### python語法學習 運算篇 :::success 1.print-***輸出*** 2.=-***指定,設定*** 3.括號內的數字為-***參數*** 4.python每行起頭對齊,為同一個程式段落。 ::: --- ### 一、算術運算子 | 符號 | 用途 | |:----:|:------:| | + | | | - | | | * | | | / | | | % | 求餘數 | | ** | 次方 | | // | 求商數 | ``` python x=9 y=5 print(x □ y) # □ 內放入計算 ``` ### 二、指派運算子 | 符號 | 模式 |運算方式 輸出X | | :--------: | :--------: | :-----: | | += | x+=1 | X=x+1 | -= | x-=2 | X=x-2 *= |x*=3|X=x*3 /= |x/=4 | X=x/4 %= | x%=5| X=x%5 **= | x**=6| X=x**6 //= | x//=7| X=x//7 ``` python x=2 x*=3 #print(x)=2*3 print(x) #6 ``` --- ### 三、比較運算子 | 符號 | Name | 模式 | |:--------:|:------------------------:|:----------:| | == | 等於 | x == y | | != | 不等於 | x != y | | > | 大於 | x > y | | < | 小於 | x < y | | >= | 大於或等於 | x >= y | | <= |小於或等於 |x<=y | ``` python x=2 y=6 print(x<y) #true ``` --- ### 四、邏輯運算子 | 符號| Name |Example | | :--------: | :--------: | :---: | | and | 且 | x < 5 and x < 10 | | or | 或 |x < 5 or x < 4| | not| 皆不滿足條件 |not(x < 5 and x < 10) | --- ### 五、身份運算子 | 運算子 | 描述 | Example | |:--------: |:------------------------------------: |:----------:| | is | 如果兩個**變量*****是***同一個對象,則為True | x is y | | is not | 如果兩個**變量*****不是***同一個對象,則為True | x is not y |
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up