What is the output of the code ? Explain ? | SoloLearn: Learn to code for FREE!

+1

What is the output of the code ? Explain ?

a = 0 and 1 or 0 b = 0 and 0 or 1 c = 1 or 0 and 0 d = 0 or 1 and 0 print(a, b, c, d, sep = '')

10/31/2020 6:11:08 AM

Manish Kumar

14 Answers

New Answer

+6

`and` has higher preference over `or` So, a = (0 and 1) or 0 # and likewise others

+6

@vrintle I think the word "precedence" suits ur comment rather than "preference". But after all the idea is conveyed.. :)

+5

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/

+4

0110 if ur code is correct. But it shows EOL error so u should correct it like print(a,b,c,d,sep="")

+4

Manish Kumar wlcm.

+2

Yeah, Alphin K Sajan, nice catch!

+1

Alphin K Sajan how ? Can you explain ? And btw I have used single quote instead of double ; )

+1

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"

+1

Alphin K Sajan thank you again for letting us know the suitable word :))

+1

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

+1

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)

+1

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

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

-1

First of all let me know what does this sep = " means ?