In Python, a string (str) is an immutable sequence of Unicode characters used to represent text data. Defined using single, double, or triple quotes, strings support sequence operations like positive and negative indexing, advanced slicing ([start:stop:step]), concatenation (+), and repetition (*). Because strings are immutable, attempting to modify a string character in place raises a TypeError. Python provides a comprehensive suite of built in string methods including .split(), .join(), .strip(), .replace(), .find(), and .startswith() as well as string formatting techniques like f-strings and .format(). Mastering Python strings is essential for text parsing, data cleaning, web scraping, and passing technical coding assessments.
Python Strings MCQs
1 min read
Correct Answer: c) Unicode code points
Explanation:
Python 3 strings are sequences of Unicode code points (UCS-2 or UCS-4 depending on the build), abstracting away the physical byte encoding.
Correct Answer: b) False
Explanation:
An empty string in Python evaluates to False in a boolean context, as it is considered falsy.
Correct Answer: a) Prefix the string with 'r' or 'R'
Explanation:
Raw strings are prefixed with 'r' or 'R', which disables backslash escape sequences such as \n or \t.
Correct Answer: a) abcdef
Explanation:
The addition operator (+) performs string concatenation, joining two or more strings together without extra spaces.
Correct Answer: b) isalnum()
Explanation:
The isalnum() method returns True if all characters in the string are alphanumeric (either letters or numbers) and there is at least one character.
Correct Answer: b) n
Explanation:
Negative indexing in Python counts from the right end of the sequence, where -1 represents the last character, which is 'n'.
Correct Answer: c) split()
Explanation:
The split() method splits a string into a list using a specified separator (defaulting to any whitespace).
Correct Answer: a) 2
Explanation:
The find() method returns the lowest index where the substring is found. In 'Hello', the first 'l' appears at index 2.
Correct Answer: b) bytes
Explanation:
The encode() method returns a bytes object representing the string encoded in the specified encoding (defaulting to UTF-8).
Correct Answer: c) ^
Explanation:
In Python's format mini-language, the caret character (^) specifies that the string should be centered within the available field width.
Correct Answer: c) A TypeError is raised
Explanation:
Because strings are immutable objects in Python, item assignment triggers a TypeError.
Correct Answer: a) "hello"
Explanation:
The strip() method removes both leading and trailing whitespace characters from the string.
Correct Answer: b) chr()
Explanation:
The chr() function takes an integer (Unicode code point) and returns the string representing that character. ord() does the reverse.
Correct Answer: a) True
Explanation:
The startswith() method checks if the string begins with the specified prefix, returning True in this case.
Correct Answer: a) True
Explanation:
isdigit() returns True if all characters in the string are digits and there is at least one character.
Correct Answer: a) f"Value is {variable}"
Explanation:
Formatted string literals (f-strings) prefix the string with 'f' or 'F' and embed expressions inside curly braces.
Correct Answer: a) "00abc"
Explanation:
The zfill() method pads the string on the left with ASCII '0' digits to reach the specified width.
Correct Answer: a) "azzle"
Explanation:
The replace() method replaces all occurrences of the substring 'p' with 'z', transforming 'apple' into 'azzle'.
Correct Answer: b) 1
Explanation:
The newline character '\n' is treated as a single escape sequence character, so the length of the string containing only '\n' is 1.
Correct Answer: c) count()
Explanation:
The count() method returns the number of times a specified substring occurs within the given range or string.
Correct Answer: a) "Hello World"
Explanation:
The title() method capitalizes the first letter of every word in the string.
Correct Answer: b) nohtyP
Explanation:
A step of -1 in string slicing reverses the entire string sequence.
Correct Answer: a) in
Explanation:
The 'in' operator checks if a substring exists within a string (e.g., 'Py' in 'Python').
Correct Answer: a) "a,b,c"
Explanation:
The join() method concatenates the elements of an iterable (like a list of strings) using the string it is called on as a separator.
Correct Answer: a) ("Py", "th", "on")
Explanation:
partition() searches for the separator and returns a 3-tuple containing the part before, the separator itself, and the part after.
Correct Answer: b) False
Explanation:
isupper() checks if all cased characters in the string are uppercase. Since 'test' is lowercase, it returns False.
Correct Answer: b) True
Explanation:
Any non-empty string in Python, even one containing the text "False", evaluates to True when converted to a boolean.
Correct Answer: a) endswith()
Explanation:
The endswith() method returns True if the string ends with the specified suffix, otherwise False.
Correct Answer: a) Replaces tabs with 4 spaces
Explanation:
expandtabs() replaces tab characters ('\t') in the string with spaces, using the specified tab size (default is 8).
Correct Answer: b) False
Explanation:
String comparisons in Python are case-sensitive. Lowercase 'abc' is not equal to uppercase 'ABC'.
Correct Answer: b) casefold()
Explanation:
The casefold() method is stronger than lower() and is used for aggressive case-insensitive string comparisons.
Correct Answer: a) "Python****"
Explanation:
ljust() left-aligns the string in a string of length 10, padding the right side with the specified fill character '*'.
Correct Answer: a) True
Explanation:
Strings are compared lexicographically (character by character based on Unicode code points). 'c' comes before 'd'.
Correct Answer: c) \r
Explanation:
\r is the escape sequence for a carriage return, while \n represents a newline.
Correct Answer: a) ""
Explanation:
Joining an empty iterable of strings returns an empty string.
Correct Answer: a) It returns an empty string
Explanation:
When slicing with a positive step, if the start index is greater than or equal to the end index, Python returns an empty string rather than throwing an error.
Correct Answer: a) string
Explanation:
The built-in 'string' module contains constants like string.ascii_letters and classes like string.Template.
Correct Answer: a) "Hello"
Explanation:
The capitalize() method returns a copy of the string with its first character capitalized and the rest lowercased.
Correct Answer: a) 65
Explanation:
The ord() function returns the integer Unicode code point of a given character. For uppercase 'A', it is 65.
Correct Answer: a) True
Explanation:
isalnum() returns True because all characters in 'abc123' are either letters or numbers.
Correct Answer: a) True
Explanation:
isspace() returns True if there are only whitespace characters in the string and there is at least one character.
Correct Answer: a) splitlines()
Explanation:
The splitlines() method splits a string at universal newlines and returns a list of the lines.
Correct Answer: a) "5"
Explanation:
Inside an f-string expression braces, expressions are evaluated at runtime, resulting in "5".
Correct Answer: a) 1
Explanation:
The index() method returns the index of the first occurrence of the substring. In 'Python', 'y' is at index 1.
Correct Answer: b) It raises a ValueError
Explanation:
Unlike find(), which returns -1 when a substring is missing, index() raises a ValueError.
Correct Answer: a) ""
Explanation:
Slicing indices out of bounds do not throw errors in Python; instead, they are gracefully truncated, resulting in an empty string.
Correct Answer: a) rstrip()
Explanation:
The rstrip() method removes trailing characters (whitespace by default) from the right end of the string.
Correct Answer: a) "PYTHON"
Explanation:
swapcase() converts all uppercase characters to lowercase and all lowercase characters to uppercase. For lowercase 'python', it returns 'PYTHON'.
Correct Answer: a) ["a", "b", "c"]
Explanation:
When split() is called without arguments, it splits by any whitespace and discards consecutive whitespace blocks.
Correct Answer: a) zfill()
Explanation:
zfill() pads strings on the left with zeros to match a specified width.
Correct Answer: c) 5
Explanation:
'abc' counts as 3, '\r' as 1, and '\n' as 1, totaling 5 characters.
Correct Answer: a) 1
Explanation:
rfind() searches for the highest index where the substring is found, returning 1 for 'b' in 'abc'.
Correct Answer: a) *
Explanation:
The multiplication operator (*) performs string repetition when combined with an integer.
Correct Answer: b) False
Explanation:
istitle() returns True if the string is titlecased (words start with an uppercase character followed by lowercase). 'hello' is all lowercase, so it returns False.
Correct Answer: a) True
Explanation:
isnumeric() returns True if all characters in the string are numeric characters (including digits, fractions, roman numerals, etc.).
Correct Answer: a) Triple quotes (""" or ''')
Explanation:
Triple quotes allow strings to span multiple lines naturally without requiring explicit newline escape sequences.
Correct Answer: a) "Jython"
Explanation:
The translate() method maps characters using a translation table created by str.maketrans(), replacing 'P' with 'J'.
Correct Answer: a) "--abc--"
Explanation:
center() pads the string with the specified fill character '-' on both sides to achieve a total width of 7.
Correct Answer: a) ["a,b", "c"]
Explanation:
rsplit() splits the string starting from the right. With maxsplit=1, it performs a single split from the right end.
Correct Answer: a) islower()
Explanation:
islower() returns True if all cased characters in the string are lowercase and there is at least one cased character.
Correct Answer: a) b'abc'
Explanation:
Encoding a string returns a bytes literal object, denoted with a leading 'b'.
Correct Answer: a) Converts bytes back to a string
Explanation:
The decode() method on bytes objects decodes the byte sequence into a standard Python string using the specified encoding.
Correct Answer: a) "st"
Explanation:
Introduced in Python 3.9, removeprefix() removes the specified prefix string if present, returning 'st'.
Correct Answer: a) "te"
Explanation:
Introduced in Python 3.9, removesuffix() removes the specified suffix string if present, returning 'te'.
Correct Answer: a) "00123"
Explanation:
The format specifier '05d' formats an integer as a decimal zero-padded to a width of 5 characters.
Correct Answer: b> Only strings resembling identifiers are automatically interned
Explanation:
Python automatically interns strings that look like valid identifiers (e.g., variable names) for optimization, and sys.intern() can be used explicitly.
Correct Answer: a) 1
Explanation:
rindex() returns the highest index where the substring is found, raising a ValueError if it is not present.
Correct Answer: a) ("Python", "", "")
Explanation:
If the partition separator is not found, partition() returns the full string followed by two empty strings.
Correct Answer: a) "abc "
Explanation:
ljust() pads the string on the right with spaces to fill the total width of 5.
Correct Answer: a) str.format_map()
Explanation:
format_map() works like format() but takes a mapping (such as a dictionary) directly without unpacking.
Correct Answer: a) True
Explanation:
A string containing a space character is non-empty, so it evaluates to True in Python.
Correct Answer: a) True
Explanation:
isupper() checks if all cased characters in the string are uppercase, returning True for 'HELLO'.
Correct Answer: a) ""
Explanation:
Multiplying a string by 0 or a negative integer results in an empty string.
Correct Answer: a) isidentifier()
Explanation:
isidentifier() returns True if the string is a valid identifier according to Python language definitions.
Correct Answer: a) ("a", "b", "c")
Explanation:
rpartition() splits the string around the last occurrence of the separator, returning a 3-tuple.
Correct Answer: a) "python "
Explanation:
lstrip() removes leading whitespace characters from the left end of the string.
Correct Answer: b) "0b1010"
Explanation:
The format specifier '0b' formats an integer as a binary number with the '0b' prefix.
Correct Answer: a) swapcase()
Explanation:
swapcase() inverts the case of all cased characters in the string.
Correct Answer: a) 7
Explanation:
Python strings can contain embedded null bytes ('\x00'), which count as valid characters, making the length 7.
Correct Answer: a) ["abc"]
Explanation:
If the split separator is not found in the string, split() returns a list containing the original string as its sole element.
Correct Answer: a) Double the braces ({{ or }})
Explanation:
To display a literal brace character inside an f-string, you must escape it by doubling it: {{ or }}.
Correct Answer: a) "Pto"
Explanation:
A slice with a step of 2 picks every second character starting from index 0 ('P', 't', 'o').
Correct Answer: a) True
Explanation:
isalpha() returns True if all characters in the string are alphabetic and there is at least one character.
Correct Answer: a) False
Explanation:
isdecimal() returns True only if all characters are decimal characters and there is at least one character. The dot '.' is not a decimal character.
Correct Answer: a) zfill()
Explanation:
zfill() pads the string on the left with ASCII '0' digits.
Correct Answer: a) True
Explanation:
The 'in' operator checks substring membership, returning True because 'abc' is present at the beginning of 'abcdef'.
Correct Answer: a) "ABC"
Explanation:
The upper() method converts all lowercase characters in the string to uppercase.
Correct Answer: a) -1
Explanation:
If the substring is not found using find(), Python returns -1 rather than raising an exception.
Correct Answer: a) translate()
Explanation:
The translate() method can take a translation table and an optional deletechars argument to remove characters.
Correct Answer: a) "1,234,567"
Explanation:
The comma specifier (,) in format strings uses commas as thousands separators.
Correct Answer: a) Converts it to uppercase
Explanation:
capitalize() transforms the first character of the string to uppercase and ensures the remaining characters are lowercase.
Correct Answer: a) TypeError
Explanation:
Python does not implicitly convert integers to strings during addition (+), raising a TypeError. String repetition requires the multiplication operator (*).
Correct Answer: a) re
Explanation:
The 're' module is Python's built-in library for regular expression pattern matching and string searching.
Correct Answer: a) ["a", "b"]
Explanation:
splitlines() breaks the string at newline boundaries, returning a list of individual lines.
Correct Answer: a) "00abc"
Explanation:
rjust() right-aligns the string to a width of 5, filling the left side with the character '0'.
Correct Answer: a) True
Explanation:
"None" is a non-empty string containing characters, so it evaluates to True (unlike the actual NoneType object, which is falsy).
Correct Answer: a) format()
Explanation:
The str.format() method allows robust string formatting using curly braces as placeholders.
Correct Answer: a) "python"
Explanation:
casefold() returns a lowercased version of the string suitable for caseless comparisons.
Correct Answer: a) "3.14"
Explanation:
The format specifier '.2f' formats a floating-point number fixed to two decimal places.
Correct Answer: a) Raises a ValueError
Explanation:
Slice step values cannot be zero in Python; attempting to use a step of 0 raises a ValueError.
Correct Answer: a) 0
Explanation:
The count() method can accept optional start and end slice parameters. In 'abc', searching for 'a' between indices 1 and 3 yields 0 occurrences because 'a' is at index 0.
Correct Answer: a) str()
Explanation:
The str() constructor or built-in function returns an informal or printable string representation of an object.
Related Posts
New
New
New

Top Python Fundamentals MCQs & Answers for Beginners
Python is a dynamically typed, high-level programming language created by Guido van Rossum in 1991. Renowned for its clear syntax…
August 27, 2026By MCQs Generator

Python Control Flow MCQs
Control flow statements regulate the order in which individual code statements are evaluated and executed in a Python program. Python…
August 27, 2026By MCQs Generator

Latest Python Loops MCQs
Loops in Python provide the fundamental mechanism for executing a block of code repeatedly until a specified condition is met…
August 27, 2026By MCQs Generator
Related Categories
New












AI & Data Science MCQ
5 topics
By MCQs Generator
New
Arts & Humanities MCQ
4 topics
By MCQs Generator
New
Civil Engineering MCQ
4 topics
By MCQs Generator
New
Commerce & Business MCQ
4 topics
By MCQs Generator
New
Competitive Exams MCQ
5 topics
By MCQs Generator
New
Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator
New
General Knowledge MCQ
2 topics
By MCQs Generator
New
General Science MCQ
4 topics
By MCQs Generator
New
Law & Judiciary MCQ
3 topics
By MCQs Generator
New
Mechanical Engineering MCQ
4 topics
By MCQs Generator
New
Medical & Health Sciences MCQ
4 topics
By MCQs Generator
New
Modern Tech Fields MCQ
3 topics
By MCQs Generator