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
- As 0 < 5 is True so b value of b becomes True and its type is bool.
print (a == b)
gives True as a and b both are True.print (a is b)
gives True as a and b both being True point to the same object in memory.- Similarly
print (c == d)
andprint (c is d)
give True as c and d both are string and point to the same object in memory. - The user input for e is True so e is of type string having value "True".
- As value of strings c and e is "True" so
print (c == e)
gives True. - 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
Find the errors(s)
a = bool (0) b = bool (1) print (a == false) print (b == true)
What is the output produced by following code?
a, b = bool(0), bool(0.0) c, d = str(0), str(0.0) print (len(a), len(b)) print (len(c), len(d))
Given a string s = "12345". Can you write an expression that gives sum of all the digits shown inside the string s i.e., the program should be able to produce the result as 15 (1+2+3+4+5).
[Hint. Use indexes and convert to integer]Find the errors(s)
name = "HariT" print (name) name[2] = 'R' print (name)