Contents

If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.
a) obj.__str__()   
b) str(obj)
c) print obj                           
d) all of these

d

Explanation: Execute in shell to verify.


To check whether string s1 contains another string s2, use………..
a) s1.__contains__(s2)
b) s2 in s1
c) s1.contains(s2)
d) si.in(s2)

a

Explanation: s2 in s1 works in the same way as calling the special function __contains__ .


Suppose i is 5 and j is 4, i + j is same as ………
a) i.__add(j)                         
b) i.__add__(j)
c) i.__Add(j)                        
d) i.__ADD(j)

b

Explanation: Execute in shell to verify.


What function do you use to read a string?
a) input(“Enter a string”)
b) eval(input(“Enter a string”))
c) enter(“Enter a string”)
d) eval(enter(“Enter a string”))

a

Explanation: Execute in shell to verify.



Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).
a) __345.355                       
b) ___345.355
c) ____345.355  
d) _____345.354

b

Explanation: Execute in the shell to verify.