運算符 | 描述 |
---|---|
[] [:] | 下標,切片 |
** | 指數 |
~ + - | 按位取反, 正負號 |
* / % // | 乘,除,模,整除 |
+ - | 加,減 |
>> << | 右移,左移 |
& | 按位與 |
^ | | 按位異或,按位或 |
<= < > >= | 小於等於,小於,大於,大於等於 |
== != | 等於,不等於 |
is is not | 身份運算符 |
in not in | 成員運算符 |
not or and | 邏輯運算符 |
= += -= *= /= %= //= **= &= ` | = ^= >>= <<=` |
複合運算example:
a = 10 b = 3 a += b #相當於:a = a + b a *= a + 2 #相當於:a = a * (a + 2)
練習:
Day1
Day1
"""練習1:華氏溫度轉換為攝氏溫度。提示:華氏溫度到攝氏溫度的轉換公式為:$C=(F - 32) \div 1.8$。 """ f = float(input('輸入華氏溫度:')) c = (f-32) / 1.8print('輸入華氏溫度 %0.1f, 攝氏溫度 %0.1f' % (f,c))
Day2
# -*- coding: UTF-8 -*-"""英制单位英寸和公制单位厘米互换 1 mm = 0.03937 in Version: 0.1 """ value = float(input("Please input value:")) unit = input("Is 'in' or 'mm'? ") if unit == "mm": newvlaue = value * 0.03937 print(" %f mm == %f in" % (value, newvlaue)) else: newvalue = value / 0.03937 print(" %f in == %f mm" % (value, newvlaue))
PyDev console: starting.
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
runfile('D:/Python_project/Day1/Test.py', wdir='D:/Python_project/Day1')
Please input value:>? 500
Is 'in' or 'mm'? >? mm
500.000000 mm == 19.685000 in
沒有留言:
張貼留言