Python is widely used in interviews, coding tests, and real-world projects. Strings and variables are foundational concepts that often appear in both technical rounds and online coding assessments.
This blog post provides 15 multiple-choice questions (MCQs) to help you practice and strengthen your Python fundamentals.
MCQ 1
Which of the following is a valid variable name in Python?
A) 1variable
B) my-variable
C) _name
D) for
Answer: C) _name
Explanation: Variable names cannot start with a number, cannot use hyphens, and cannot be Python keywords.
MCQ 2
What is the output of:
A) Pyt
B) yth
C) hon
D) Pyth
Answer: B) yth
Explanation: String slicing [start:end] includes start index but excludes end index.
MCQ 3
Which statement about Python strings is True?
A) Strings are mutable
B) Strings are immutable
C) Strings cannot be sliced
D) Strings can only contain letters
Answer: B) Strings are immutable
MCQ 4
How do you convert the string "123" into an integer?
A) int("123")
B) str("123")
C) float("123")
D) convert("123")
Answer: A) int("123")
MCQ 5
What will be the output of:
A) False
B) True
C) Error
D) None
Answer: B) True
Explanation: is checks object identity. Both variables point to the same string object.
MCQ 6
Which of the following is the correct way to take string input from a user?
A) input()
B) scanf()
C) cin >>
D) read()
Answer: A) input()
MCQ 7
What does len("Python") return?
A) 5
B) 6
C) 7
D) Error
Answer: B) 6
Explanation: The len() function returns the number of characters in a string.
MCQ 8
Which of the following will convert an integer to a string?
A) str(10)
B) int("10")
C) float(10)
D) string(10)
Answer: A) str(10)
MCQ 9
What will s = "Python"; s[0] = "p" do?
A) Change the first character
B) Throw an error
C) Replace all characters
D) None
Answer: B) Throw an error
Explanation: Strings are immutable; individual characters cannot be changed.
MCQ 10
How do you reverse a string s = "hello"?
A) s.reverse()
B) s[::-1]
C) reverse(s)
D) s.reverse_string()
Answer: B) s[::-1]
MCQ 11
Which of the following joins a list of words into a single string?
A) " ".join(words)
B) words.join(" ")
C) join(words)
D) " ".concat(words)
Answer: A) " ".join(words)
MCQ 12
What will be the output of:
A) 1
B) 2
C) 3
D) Error
Answer: C) 3
Explanation: count() returns the number of occurrences of a character.
MCQ 13
Which of these will check if a variable x is a string?
A) type(x) == "str"
B) isinstance(x, str)
C) x.isstring()
D) str(x)
Answer: B) isinstance(x, str)
MCQ 14
What will s = " Python "; print(s.strip()) return?
A) "Python"
B) " Python "
C) "Python "
D) " Python"
Answer: A) "Python"
Explanation: strip() removes leading and trailing whitespace.
MCQ 15
Which of the following correctly swaps two variables without a temporary variable?
A) a = b; b = a
B) a, b = b, a
C) swap(a, b)
D) a = a + b; b = a - b; a = a - b
Answer: B) a, b = b, a
🎓 Conclusion
These 15 MCQs on Python Strings & Variables cover the most common topics asked in interviews and coding rounds. Regular practice will strengthen your understanding of:
-
Variable naming rules
-
String indexing and slicing
-
String methods (
strip,join,count) -
Type conversions (
int,str) -
Python fundamentals like immutability and variable swapping
🔥 Boost Your Python Skills with Eduarn
If you want to master Python and get interview-ready, check out our industry-focused courses at Eduarn.com.
-
Live coding sessions
-
Real-world projects
-
Interview preparation material
-
Beginner to advanced level learning
Learn Python, build your career, and crack your dream job with Eduarn.

No comments:
Post a Comment