Python Questions and Answers – Strings – 2
This set of Advanced Python Interview Questions & Answers focuses on “Strings”.
4. What is the output of the following code ?
a) Error
b) -1
c) 1
d) 0
View Answer
1. What is the output of the following code ?
a) None None
b) None 22
c) 22 None
d) Error is generated
View Answer
b) None 22
c) 22 None
d) Error is generated
View Answer
Answer:d
Explanation:self.o1 was never created.
Explanation:self.o1 was never created.
2. What is the output of the following code ?
a) 224
b) Error
c) 12
d) None
View Answer
b) Error
c) 12
d) None
View Answer
Answer:c
Explanation:id in this case will be the attribute of the class.
Explanation:id in this case will be the attribute of the class.
3. What is the output of the following code ?
a) wo
b) world
c) sn
d) rl
View Answer
b) world
c) sn
d) rl
View Answer
Answer:a
Explanation:Execute in the shell and verify.
Explanation:Execute in the shell and verify.
advertisements
a) snow
b) snow world
c) Error
d) snos world
View Answer
b) snow world
c) Error
d) snos world
View Answer
Answer:c
Explanation:Strings cannot be modified.
Explanation:Strings cannot be modified.
5. What is the output of the following code ?
a) Error
b) u
c) t
d) y
View Answer
b) u
c) t
d) y
View Answer
Answer:d
Explanation:Max returns the character with the highest ascii value.
Explanation:Max returns the character with the highest ascii value.
6. Given a string example=”hello” what is the output of example.count(l)
a) 2
b) 1
c) None
d) 0
View Answer
a) 2
b) 1
c) None
d) 0
View Answer
Answer:a
Explanation:l occurs twice in hello.
Explanation:l occurs twice in hello.
7. What is the output of the following code ?
advertisements
b) -1
c) 1
d) 0
View Answer
Answer:c
Explanation:returns lowest index .
Explanation:returns lowest index .
8. What is the output of the following code ?
a) -1
b) 4
c) 3
d) 1
View Answer
b) 4
c) 3
d) 1
View Answer
Answer:b
Explanation:returns highest index.
Explanation:returns highest index.
9. What is the output of the following code ?
a) dlrowolleh
b) True
c) -1
d) None
View Answer
b) True
c) -1
d) None
View Answer
Answer:b
Explanation:Starts with checks if the given string starts with the parameter that is passed.
Explanation:Starts with checks if the given string starts with the parameter that is passed.
10. To concatenate two strings to a third what statements are applicable (multiple answers are allowed) ?
a) s3 = s1 + s2
b) s3 = s1.add(s2)
c) s3 = s1.__add__(s2)
d) s3 = s1 * s2
View Answer
a) s3 = s1 + s2
b) s3 = s1.add(s2)
c) s3 = s1.__add__(s2)
d) s3 = s1 * s2
View Answer
Answer:a,c
Explanation:__add__ is another method that can be used for concatenation.
Explanation:__add__ is another method that can be used for concatenation.
No comments:
Post a Comment