當前位置

首頁 > 教育範文 > 工作總結 > 數學代數教學總結

數學代數教學總結

推薦人: 來源: 閱讀: 1.39W 次
數學代數教學總結
數學代數教學總結
在學習vb過程中,很多同學簡單地認爲布爾值true就是-1或非0值,false就是0,這種看法是錯誤,下面將布爾值、邏輯運算和關係運算總結如下:
在vb中,布爾(boolean)值有兩個:true(真)和false(假),布爾值可以用於邏輯、關係(比較)和算術運算中。
1)布爾值用於邏輯運算中,結果爲布爾值。
例如:
print not true, not false
print true and true, true and false, false and true, false and false
print true or true, true or false, false or true, false or false
結果爲:
false true
truefalsefalsefalse
truetrue true false
【總結】
not 非運算規則:非真則假,非假則真
and 與運算規則:只有都是true,結果才爲true(只要有一個爲false,結果就爲false)
or 或運算規則:只有都是false,結果才爲false(只要有一個爲true,結果就爲true)
2)布爾值用於關係(比較)運算中,結果爲布爾值。
例如:
print true > false
結果爲:
false
【總結】在關係運算中,true小於false。
3)布爾值用於算術運算中(true當作-1,false當作0),結果爲數值型。
例如:
print true + 3, false + 3
結果爲:
2 3
----------------------------------------------------------------------------
1)邏輯運算說明
數值用於邏輯運算中,非0值當作true,0當作false,結果爲數值型。
注:true and n和false or n的結果爲n,其他情況true寫成-1,false寫成0(即結果可能爲n、-1或0)
例如:
print true and 5, true and 0, false and 5, false and 0
print true or 5, true or 0, false or 5, false or 0
結果爲: 5 0 0 0
-1-1 5 0
【注意】布爾值可用於算術運算;數值可以用於邏輯運算。但不能認爲true和-1、false和0完全等價。
● 算術運算的結果必然爲數值型。
● 關係運算(比較運算)的結果必然是布爾值。
● 邏輯運算的結果可能是布爾值或是數值型。
2)關係(比較)運算說明
數值、日期、字符和布爾值都可以比較。
● 日期比較的規則是“日期在後的大”
● 字符比較的規則是按照ascii碼比較,空格<"0"-"9"<"a"-"z"<"a"-"z"<漢字
● 布爾值比較的規則是假大於真。
例如:
print 3 < 5
print #9/19/2009# > #9/18/2009#
print "abc" > "abcd"
print true > false
結果爲:
true
true
false
false
例題:
【XX年4月】
您現在閱覽的是南京便民網謝謝您的支持和鼓勵!!!
(16)設a=4,b=3,c=2,d=1,下列表達式的值是
a>b+1 or c
a)trueb)1c)-1d)0
【分析】
a>b+1 即 4>3+1 結果爲 false。
c
b mod c即3 mod 2結果爲 1。
即false or false and 1。and優先級高於or,false and 1結果爲0。
false or 0的結果爲0.
所以本題答案爲0 。