KnowledgeBoat Logo

Computer Science

Predict the output if e is given input as 'True':

a = True
b = 0 < 5
print (a == b) 
print (a is b)
c = str (a)
d = str (b)
print (c == d) 
print (c is d)
e = input ("Enter :")
print (c == e) 
print (c is e)

Python

Python Data Handling

25 Likes

Answer

True
True
True
True
Enter :True
True
False

Working

  1. As 0 < 5 is True so b value of b becomes True and its type is bool.
  2. print (a == b) gives True as a and b both are True.
  3. print (a is b) gives True as a and b both being True point to the same object in memory.
  4. Similarly print (c == d) and print (c is d) give True as c and d both are string and point to the same object in memory.
  5. The user input for e is True so e is of type string having value "True".
  6. As value of strings c and e is "True" so print (c == e) gives True.
  7. Even though the values of strings c and e are same, they point to different objects in memory so print (c is e) gives False.

Answered By

12 Likes


Related Questions