標籤:copyright 電腦 關鍵字 運算式 底線
[[email protected] ~]# pythonPython 2.6.6 (r266:84292, Jan 22 2014, 09:37:14)[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> a=1>>> print a1>>> a1=2>>> a_1=3# 查詢a在記憶體當中的地址>>> id(a)142437776# 一個值可以擁有多個標籤>>> b=1>>> id(b)142437776
>>> a=100>>> a=a-50>>> a50>>> a=100>>> a-=50>>> a50
- 算術運算子(“+”,“-”,“*”,“/”,“//”,“%”,“**”)
>>> 1+12>>> 3-21>>> 3*412>>> 4/22>>> 5/22>>> 3.0/21.5>>> 3.0//21.0>>> 17%65>>> 3**327>>> 3**29
- 關係運算子(“<”,“>”,“<=”,“>=”,“!=”,“==”),布爾值
>>> 1>2False>>> 1<2True>>> 1<=2True>>> 1>=2False>>> 1!=2True>>> 1==2False
- 邏輯運算子(“and”,“or”,“not”)
>>> 1>2 and 1<2False>>> 1>2 or 1<2True>>> not 1<2False>>> not 1>2True
運算子的優先順序
在同意運算式中,高優先順序的先運算
同層級的運算子,按從左至右處理
運算子的優先順序,由低到高為:
Lambda
邏輯運算:or
邏輯運算:and
邏輯運算:not
成員測試:in,not in
同一性測試:is,is not
比較:<,<=,>>=,!=,==
按位或:|
按位異或:^
按位與:&
位移:<<,>>
加法與減法:+,-
乘法、除法與取餘:*,/,%
加號或減號:+x,-x
按位翻轉:~x
指數:**
擷取鍵盤值
#!/usr/bin/python
a=int(raw_input("please input num1 :"))
b=int(raw_input("please input num2 :"))
本文出自 “Topspeed_King” 部落格,請務必保留此出處http://mylinuxlife.blog.51cto.com/4706737/1664122
Python變數、運算子與運算式