【備忘録】and or 演算(1 and 2 #2 / 1 or 2 #1)

python3
あくまで備忘録なんで雑に記録します

結論
andは左から、偽なら左、違えば右
orは左から、真なら左、違えば右
1 and 2 は、2
2 or  1 は、1

True Falseはわかりやすい

print(True and True)# True
print(True and False)# False
print(False and True)# False
print(False and False)# False

print(True or True)# True
print(True or False)# True
print(False or True)# True
print(False or False)# False

1や2(True)と0(False)ではちょっと違う

print(10 and 20)# 20
print(20 and 10)# 10
print(10 and 0)# 0
print(0 and 10)# 0
print(0 and 0)# 0

print(10 or 20)# 10
print(20 or 10)# 20
print(10 or 0)# 10
print(0 or 10)# 10
print(0 or 0)# 0
もう一度、結論
#andは左から、偽なら左、違えば右
#orは左から、真なら左、違えば右

コメント

"+r+""+h+""+">"}var c,i=n(45),u=n(74),f=n(64),s=n(53),p=n(76),l=n(41),y=(n=n(52),"prototype"),h="script",v=n("IE_PROTO"),g=function(){try{c=new ActiveXObject("htmlfile")}catch(r){}var r;g="undefined"==typeof document||document.domain&&c?function(r){r.write(a("")),r.close();var t=r.parentWindow.Object;return r=null,t}(c):((r=l("iframe")).style.display="none",p.appendChild(r),r.src=String("javascript:"),(r=r.contentWindow.document).open(),r.write(a("document.F=Object")),r.close(),r.F);for(var t=f.length;t--;)delete g[y][f[t]];return g()};s[v]=!0,t.exports=Object.create||function(t,e){var n;return null!==t?(o[y]=i(t),n=new o,o[y]=null,n[v]=t):n=g(),e===r?n:u.f(n,e)}},function(r,t,e){var n=e(5),o=e(44),a=e(43),c=e(45),i=e(11),u=e(75);t.f=n&&!o?Object.defineProperties:function(r,t){c(r);for(var e,n=i(t),o=u(t),f=o.length,s=0;s=t||56320!=(64512&i(r,e))))return!1}return!0}})},function(r,t,e){var n=e(91),o=String;r.exports=function(r){if("Symbol"===n(r))throw new TypeError("Cannot convert a Symbol value to a string");return o(r)}},function(r,t,e){var n=e(2),o=e(7),a=e(13),c=e(15),i=e(102),u=(e=e(6),Array),f=a("".charAt),s=a("".charCodeAt),p=a([].join),l="".toWellFormed,y=l&&e((function(){return"1"!==o(l,1)}));n({target:"String",proto:!0,forced:y},{toWellFormed:function(){var r=i(c(this));if(y)return o(l,r);for(var t=r.length,e=u(t),n=0;n
タイトルとURLをコピーしました