Python String Interview Questions: Python Programming

Python String Interview Questions. Multiple Choice Questions on Strings in Python Programming Language. These MCQs will help you to prepare yourself for interview questions and tests. For detailed Python Questions visit Python MCQs


Python String Interview Questions



To check whether string s1 contains another string s2 use ??

a) s1.__contains__(s2)
b) s2 in s1
c) s1.contains(s2)


The format function when applied on a string returns ??

a) Error
b) int
c) bool
d) str


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 the mentioned


Suppose s is “\t\tWorld\n” what is s.strip() ??

a) \t\tWorld\n
b) \t\tWorld\n
c) \t\tWORLD\n
d) World


Python String Interview Questions


To return the length of string s what command do we execute ??

a) s.__len__()
b) len(s)
c) size(s)
d) s.size()


Which of the following statement prints hello\example\test.txt ??

a) print(“hello\example\test.txt”)
b) print(“hello\\example\\test.txt”)
c) print(“hello\”example\”test.txt”)
d) print(“hello”\example”\test.txt”)


To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed) ??

a) s[]
b) s.getitem(3)
c) s.__getitem__(3)
d) s.getItem(3)


What is the output of statement ??


a) a
b) b
c) c
d) A


Python String Interview Questions


What is “Hello”.replace(“l”, “e”) ??

a) Heeeo
b) Heelo
c) Heleo
d) None


What would be the output of the following Python code snippet ??


a) A
b) B
c) a
d) Error


The output of the following Python code ??

print(“xyyzxyzxzxyy”.endswith(“xyy”, 0, 2))

a) 0
b) 1
c) True
d) False


The output of the following Python code is ??

print(“abcdef”.center(10, ’12’))


a) 12abcdef12
b) abcdef1212
c) 1212abcdef
d) error


Python String Interview Questions


The output of following statement in Python is ??


a) 1
b) True
c) 3
d) 2


What is the output of the following line of code ??

print(“abcdef”.center(7, ‘1’))

a) 1abcdef
b) abcdef1
c) abcdef
d) error


What is the default value of encoding in encode() ??

b) qwerty
c) utf-8
d) utf-16


Read More

Leave a Comment

error: Content is protected !!