測驗使用語言:【Python】
由于此類語言入門非常容易,哪怕初中生亦可以,并且本科/研究生寫論文、做實驗多數所用語言都是【Python】故而選擇此語言,
代碼運行平臺:【win10 x64】
代碼環境安裝:【https://blog.csdn.net/feng8403000/article/details/113784766】
代碼編碼格式:【https://blog.csdn.net/feng8403000/article/details/113785344】
完整的vs搭建并使用【Python】,非常簡單,基礎部分無需任何環境配置,工具自帶即可,
1、整數運算:【四則運算、整除、冪運算、取余、位移】
程式運算分為:【+, -, *, /, //, **, %分別表示加法或者取正、減法或者取負、乘法、除法、整除、乘方、取余,>>, <<表示右移和左移,】
x=-20#負數
y=+3#正數
print("{0}+{1}={2}".format(x,y,(x+y)))#加法
print("{0}-{1}={2}".format(x,y,(x-y)))#減法
print("{0}*{1}={2}".format(x,y,(x*y)))#乘法
print("{0}/{1}={2}".format(x,y,(x/y)))#除法
print("{0}//{1}={2}".format(x,y,(x//y)))#整除
print("{0}**{1}={2}".format(x,y,(x**y)))#冪運算
print("{0}%{1}={2}".format(x,y,(x%y)))#取模(取余)
print("{0}>>{1}={2}".format(x,y,(x%y)))#向右唯一
print("{0}<<{1}={2}".format(x,y,(x%y)))#向左位移

2、普通浮點數計算:【小數計算與位移運算】
x=-20.5#負數
y=+3.6#正數
print("{0}+{1}={2}".format(x,y,(x+y)))#加法
print("{0}-{1}={2}".format(x,y,(x-y)))#減法
print("{0}*{1}={2}".format(x,y,(x*y)))#乘法
print("{0}/{1}={2}".format(x,y,(x/y)))#除法
print("{0}//{1}={2}".format(x,y,(x//y)))#整除
print("{0}**{1}={2}".format(x,y,(x**y)))#冪運算
print("{0}%{1}={2}".format(x,y,(x%y)))#取模(取余)
print("{0}>>{1}={2}".format(x,y,(x%y)))#向右唯一
print("{0}<<{1}={2}".format(x,y,(x%y)))#向左位移

3、位運算子:【&, |, ^,~】二進制位運算
x=60#二進制:0011 1100
y=13#二進制:0000 1101
#按位與運算子:參與運算的兩個值,如果兩個相應位都為1,則該位的結果為1,否則為0
print("{0}&{1}={2}".format(x,y,(x&y)))#二進制:0000 1100
#按位或運算子:只要對應的二個二進位有一個為1時,結果位就為1,
print("{0}|{1}={2}".format(x,y,(x|y)))#二進制:0011 1101
#按位異或運算子:當兩對應的二進位相異時,結果為1
print("{0}^{1}={2}".format(x,y,(x^y)))#二進制:0011 0001
#按位取反運算子:對資料的每個二進制位取反,即把1變為0,把0變為1 ,~x 類似于 -x-1
print("~{0}".format(~x))#1100 0011

4、邏輯運算【and、or、not】
| 運算子 | 邏輯運算式 | 描述 | 實體 |
|---|---|---|---|
| and | x and y | 布爾"與" - 如果 x 為 False,x and y 回傳 False,否則它回傳 y 的計算值, | (a and b) 回傳 20, |
| or | x or y | 布爾"或" - 如果 x 是非 0,它回傳 x 的值,否則它回傳 y 的計算值, | (a or b) 回傳 10, |
| not | not x | 布爾"非" - 如果 x 為 True,回傳 False ,如果 x 為 False,它回傳 True, | not(a and b) 回傳 False |
x=True
y=False
#布爾"與" 需要 and 符號前后兩者x與y都是True,結果才是True
print("{0} and {1} = {2}".format(x,y,x and y))
#布爾"或" or 符號前后兩者有一個是True,結果就是True
print("{0} or {1} = {2}".format(x,y,x or y))
#布爾"非" not 代表取相反的結果
print("not {0} = {1}".format(x,not x))

5、總結:
a)、不要小看小小的運算子號,所有的變數計算都無法離開它們的相互之間配合,
下篇內容:
程式員數學基礎【二、時間復雜度】(Python版本):
【https://blog.csdn.net/feng8403000/article/details/114193372】
萬丈高樓平地起,程式員數學基礎,從小學的【什么是數學】至【離散數學】(主要是圖論)咱們一步步成長,共同加油,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/264876.html
標籤:區塊鏈
上一篇:亞馬遜開店流程
