14 AnswersNew Answer
`and` has higher preference over `or` So, a = (0 and 1) or 0 # and likewise others
@vrintle I think the word "precedence" suits ur comment rather than "preference". But after all the idea is conveyed.. :)
Manish Kumar This is a simple question if u knw the working of AND /OR operator. Read this lesson carefully and if u still didn't understand I'll explain. https://www.sololearn.com/learn/Python/2279/
0110 if ur code is correct. But it shows EOL error so u should correct it like print(a,b,c,d,sep="")
Manish Kumar wlcm.
Yeah, Alphin K Sajan, nice catch!
Alphin K Sajan how ? Can you explain ? And btw I have used single quote instead of double ; )
Alphin K Sajan @vrintle thanks you : ) )) I was confused about the value of "c" . I was getting "0" instead of "1" , because I didn't know that "and " has higher preference over "or"
Alphin K Sajan thank you again for letting us know the suitable word :))
Muhammad Abdulmalik The separator between the arguments to print() function in Python is space by default (softspace feature) , which can be modified and can be made to any character, integer or string as per our choice. The ‘sep’ parameter is used to achieve the same. 1. print('G','F','G', sep='') #output : GFG 2. print('09','12','2016', sep= ' - ') #output : 09-12-2016 3. print('maumahad' , 'abdul', sep=' @') #output : [email protected] source:-gfg
output is “0110” a = “0 and 1 > False (0) “or 0” > False (0) result > false or false > False(0) b = “0 and 0” > False (0) “or 1” > True (1) result > false or true > True(1) ... and so on. if you use “and” operator then two value of its must be true (1 and 1) for true (1) result. next you do calculation for “or” operator and one “true” (1) value is enough for the result True “1” and if both are false (0) then result is false too (0)
Muhammad Abdulmalik sep=“” meaning is seperator. for example: result of this code is 0110 you see there is no any spaces between. if you put sep=“-“ then output will be as 0-1-1-0
AND operator evaluates LHS and RHS. It always returns the RHS unless the LHS is falsy; false/0/empty OR operator only evaluates the LHS first. It returns the LHS if it is true, otherwise it returns the RHS, even if the RHS is False So they're kinda opposites Also, AND is evaluated before OR due to operator precedence
First of all let me know what does this sep = " means ?