Python Strings MCQ Questions and Answers
Q. What is the output of the following Python code?
my_string = "Hello, World!" print(my_string[::2])A. Hell, Wrd
B. Hello, World!
C. Hell, World
D. Error: Invalid slice notation
Q. What is the output of the following Python code?
my_string = "Python is awesome" print(my_string.replace("Python", "Java"))A. Java is awesome
B. Python is Java
C. Python Java awesome
D. Error: Invalid syntax
Q. What is the output of the following Python code?
my_string = "Hello" print(my_string.upper()) print(my_string)A. HELLO
Hello
B. HELLO
hello
C. Hello
HELLO
D. Hello
hello
Q. What is the output of the following Python code?
my_string = " Python " print(my_string.strip())A. Python
B. Python
C. Python
D. Error: Invalid syntax
Q. What is the output of the following Python code?
my_string = "Hello, World!" print(my_string[3:8])A. ello,
B. lo, W
C. lo, Wo
D. Error: Invalid slice notation
Q. What is the output of the following Python code?
my_string = "Hello" print(my_string.isalpha())A. True
B. False
C. Error: Invalid method
Q. What is the output of the following Python code?
my_string = "Hello, World!" print(my_string.startswith("Hello"))A. True
B. False
C. Error: Invalid method
Q. What is the output of the following Python code?
my_string = "Hello" print(my_string.find("ell"))A. 1
B. 2
C. -1
D. Error: Invalid method
Q. What is the output of the following Python code?
my_string = "Hello, World!" print(my_string.split(","))A. ['Hello', ' World!']
B. ['Hello', 'World']
C. ['Hello, World!']
D. Error: Invalid method
Q. What is the output of the following Python code?
my_string = "Hello" print(my_string.isalnum())A. True
B. False
C. Error: Invalid method