+ 3

What is the different between (and , &) and (or, | )

7th May 2018, 2:49 PM
Omar
Omar - avatar
22 Answers
+ 5
Omar o what do you mean by 5 and 6=>6,tell me
7th May 2018, 4:30 PM
Maninder $ingh
Maninder $ingh - avatar
+ 4
And (&&) can mean that both values have to be true while Or (||) can mean that either one of the values have to be true. If one is true and another is false, then it's still considered as true.
7th May 2018, 2:55 PM
silentlearner
silentlearner - avatar
+ 4
and , or= Do logical things. &,|=used in binary print(4&3) 4 in binary=100 3 in binary=011 output= 000 where 0=False ,1=True
7th May 2018, 4:19 PM
Maninder $ingh
Maninder $ingh - avatar
+ 4
Omar o print(5 and 6) returns 6 because in a logical test, the value to be returned will be the value evaluated last. (It's written in the link I posted.) print(5 & 6) will return 4.
7th May 2018, 4:42 PM
silentlearner
silentlearner - avatar
+ 4
Omar o Yes. However, as Dario mentioned, if the first expression is 0 (0 and 5), then 0 will be printed. Because 0 means false. If the first expression is false, the first expression will be printed and the second expression is never evaluated.
7th May 2018, 5:49 PM
silentlearner
silentlearner - avatar
+ 3
I'm not sure about Python but in most other languages the word and the symbol for comparing values are almost identical. The only difference is the order it's evaluated. "&" and "|" will be evaluated before "and" and "or".
7th May 2018, 3:01 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
7th May 2018, 3:54 PM
silentlearner
silentlearner - avatar
+ 2
Omar o Sorry I think I misinterpreted your question. I thought you ment the difference between the symbol and the word. silentlearner's answer is correct.
7th May 2018, 3:23 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 2
(and, or) are logic operators in true/false statement. Ex: if a<b and a<c : min=a (&, |) are "bit by bit" operators. They works with binary representation of two numbers: Ex: 5 & 6 => 4 In fact 101 & 110 => 100
7th May 2018, 3:30 PM
Dario
Dario - avatar
+ 2
"and" is not born to compare two numbers but two statments. It returns the last one... only if they are different from zero... "&" is a binary operator instead.
7th May 2018, 3:58 PM
Dario
Dario - avatar
+ 2
only if the first one is different from zero... but the code "5 and 6" hasn't got any meaning, instead "5&6" has
7th May 2018, 5:24 PM
Dario
Dario - avatar
+ 1
but u understand my quistion well.....I really meant this
7th May 2018, 3:25 PM
Omar
Omar - avatar
+ 1
in every time the output will be the number in the right ??(4) silentlearner
7th May 2018, 5:01 PM
Omar
Omar - avatar
+ 1
Thanks guys😀
7th May 2018, 8:28 PM
Omar
Omar - avatar
0
u mean that there is no deffernce between them??
7th May 2018, 3:16 PM
Omar
Omar - avatar
0
the different between or and |
7th May 2018, 3:25 PM
Omar
Omar - avatar
0
the different between and , &
7th May 2018, 3:25 PM
Omar
Omar - avatar
0
but when do this I will have 6.....why?!
7th May 2018, 3:51 PM
Omar
Omar - avatar
0
Dario 5 and 6 =>6
7th May 2018, 3:52 PM
Omar
Omar - avatar
0
but why the output is 6
7th May 2018, 4:25 PM
Omar
Omar - avatar