MCQ on Python String Methods and Functions

MCQ on Python String Methods and Functions. We covered all the MCQ on Python String Methods and Functions in this post for free so that you can practice well for the exam.

Install our MCQTUBE Android app from the Google Play Store and prepare for any competitive government exams for free.



We created all the competitive exam MCQs into several small posts on our website for your convenience.

You will get their respective links in the related posts section provided below.

Join Telegram Group and Get FREE Alerts! Join Now

Join WhatsApp Group For FREE Alerts! Join Now

Related Posts:

Questions hide

MCQ on Python String Methods and Functions for Students

What is a common way to join several strings into one in Python?

a. Using the + operator

b. Using the & operator

c. Using the concat() function

d. Using the join() method

Option a – Using the + operator

In Python, what is the index position of the first character in a string?

a. 0

b. 1

c. -1

d. 2

Option a – 0

What does string[2:5] return in Python?

a. Only the character at position 2

b. A substring from index 2 up to but not including index 5

c. The character at position 5

d. It results in an error

Option b – A substring from index 2 up to but not including index 5

What does string[:-3] return?

a. The last three characters of the string

b. A new string that excludes the final three characters

c. A string containing only the first three characters

d. This causes an error

Option b – A new string that excludes the final three characters

How do you reverse a string using Python slicing?

a. string[:-1]

b. string.reverse()

c. string.reverseSlice()

d. string[::-1]

Option a – string[:-1]

Which option correctly retrieves the last character of a string in Python?

a. string[0]

b. string[-1]

c. string[-2]

d. string[len(string)]

Option b – string[-1]

Which method returns the index of the first time a substring appears in a string?

a. find()

b. search()

c. index()

d. locate()

Option a – find()

What value does "Hello, world!".count("o") return?

a. 0

b. 1

c. 2

d. 4

Option b – 1

What method is used to swap a specific portion of a string with another one?

a. replace()

b. substitute()

c. swap()

d. change()

Option a – replace()

How do you check if a string begins with a certain set of characters?

a. starts()

b. startswith()

c. begin()

d. startswithwith()

Option b – startswith()

Which function helps determine if a string finishes with a certain suffix?

a. ends()

b. endswith()

c. endswithwith()

d. isendwith()

Option b – endswith()

What is the role of the strip() method in strings?

a. Eliminates any spaces at the start and end of a string

b. Removes spaces from within the string

c. Inserts spaces at the beginning and end

d. Makes the entire string uppercase

Option a – Eliminates any spaces at the start and end of a string

Which method checks if every character in a string is a letter or a number?

a. isalphanum()

b. isalpha()

c. isnumeric()

d. isalnum()

Option d – isalnum()

How do you make the first letter of each word uppercase in a string?

a. upper()

b. capitalize()

c. title()

d. initialCap()

Option c – title()

What is the function of the join() method in Python?

a. Converts a list of strings into a single string.

b. Combines two separate strings.

c. Deletes a portion of text from a string.

d. Divides a string into a list.

Option a – Converts a list of strings into a single string.

Which method is used to locate the final position of a substring within a string, returning -1 if it’s absent?

a. find()

b. index()

c. rfind()

d. rindex()

Option c – rfind()

How do you verify the presence of a substring within a string in Python?

a. By using the search() function

b. By using the contains() function

c. By applying the in keyword

d. By calling the find() method

Option c – By applying the in keyword

Which method is suitable for finding the last occurrence index of a substring in a string?

a. find()

b. index()

c. rfind()

d. rindex()

Option c – rfind()

If the substring “Python” is missing, what does string.find("Python") return?

a. 0

b. -1

c. None

d. An error message

Option b – -1

Which string method returns the index of a given substring if it’s found?

a. string.index(substring)

b. string.contains(substring)

c. substring in string

d. substring.search(string)

Option a – string.index(substring)

What will happen if you call string.index("Python") when “Python” is not in the string?

a. It will return -1

b. It will return None

c. It will throw a ValueError

d. It will return 0

Option c – It will throw a ValueError

Which method is used to eliminate spaces from the beginning and end of a string, but not the ones in between?

a. strip()

b. lstrip()

c. rstrip()

d. remove_whitespace()

Option a – strip()

How do you change all characters in a string to uppercase in Python?

a. string.toUppercase()

b. string.upper()

c. string.makeUpperCase()

d. string.toUpperCase()

Option b – string.upper()

Which method allows you to replace only a limited number of specific substrings in a string?

a. replace()

b. substitute()

c. replace_all()

d. replace_count()

Join Telegram Group and Get FREE Alerts! Join Now

Join WhatsApp Group For FREE Alerts! Join Now

Option a – replace()

What’s a common way to merge a list of strings into one string in Python?

a. Using the join() method

b. Using the concat() method

c. Using the + operator

d. Using the merge() function

Option a – Using the join() method

What does the splitlines() method accomplish in Python?

a. Divides a string into a list wherever line breaks occur

b. Splits a string by spaces

c. Breaks a string into characters

d. Deletes all whitespace from a string

Option a – Divides a string into a list wherever line breaks occur

What is the purpose of the .format() function in string manipulation?

a. To insert dynamic values into placeholders in a string

b. To format and display date values

c. To construct a brand-new string

d. To eliminate extra spaces

Option a – To insert dynamic values into placeholders in a string

What is the correct way to eliminate all types of whitespace from a string in Python?

a. trim()

b. strip()

c. remove_whitespace()

d. delete_whitespace()

Option b – strip()

Which function lets you extract a portion of a string by specifying start and end positions?

a. substring()

b. slice()

c. splice()

d. substr()

Option b – slice()

Which method would you use to verify that a string contains only alphabet letters?

a. isalpha()

b. isalphabet()

c. isletters()

d. isalphastring()

Option a – isalpha()

How can you modify a string so that each word starts with an uppercase letter?

a. titlecase()

b. to_title()

c. title()

d. capitalize()

Option c – title()

Which option can be used to eliminate every non-alphanumeric character from a string?

a. strip()

b. remove_non_alnum()

c. isalpha()

d. isalnum()

Option b – remove_non_alnum()

Which method helps find the last occurrence of a substring and gives its index, or -1 if not found?

a. find()

b. index()

c. rfind()

d. rindex()

Option c – rfind()

What value is returned by find("Python") if the word “Python” does not exist in the string?

a. 0

b. -1

c. None

d. An error

Option b – -1

How do you check for a substring’s presence and get its index in a string?

a. Using string.index(substring)

b. Using string.contains(substring)

c. Using substring in string

d. Using substring.search(string)

Option a – Using string.index(substring)

What happens when string.index("Python") is called and “Python” is not found?

a. Returns -1

b. Returns None

c. Raises a ValueError

d. Returns 0

Option c – Raises a ValueError

Which technique lets you get a portion from the end of a string?

a. Using substring(start, end)

b. Using negative indexing

c. Using substringFromEnd(start, end)

d. Using rsubstring() method

Option b – Using negative indexing

What method trims the spaces from only the beginning of a string?

a. strip()

b. lstrip()

c. rstrip()

d. remove_whitespace()

Option b – lstrip()

How do you convert all characters in a string to lowercase in Python?

a. string.toLower()

b. string.lower()

c. string.makeLower()

d. string.to_lowercase()

Option b – string.lower()

If you want to replace a specific number of substring occurrences, which method should you use?

a. replace()

b. substitute()

c. replace_all()

d. replace_count()

Option a – replace()

What’s the best way to combine elements of a string list into one string?

a. Using join() method

b. Using concat() method

c. Using + operator

d. Using merge() function

Option a – Using join() method

What is the correct way to create a string in Python?

a. string = Hello, World!’

b. string = “Hello, World!”

c. string =’Hello, World!’

d. All of the above

Option d – All of the above

Which of the following is an immutable data type in Python?

a. List

b. Tuple

c. String

d. Dictionary

Option c – String

How can you access the last character of a string in Python?

a. s[len(s)]

b. s[-1]

c. s[-len(s)]

d. s[0]

Option b – s[-1]

What will be the result of executing "Python".find("th")?

a. 2

b. 1

c. 3

d. -1

Option b – 1

What does the expression "abc" * 3 evaluate to in Python?

a. “abcabc”

b. “abc abc abc”

c. 9

d. [“abc”, “abc”, “ABC”]

Option a – “abcabc”

Which function is used to get the index of the first occurrence of a substring in a string?

a. substring()

b. index()

c. find()

d. search()

Option c – find()

What will be the output of "Hello, World!".count("l")?

a. 2

b. 3

c. 4

d. 5

Option b – 3

Which of the following is true about Python strings?

a. Strings can only contain alphabetic characters.

b. Strings are mutable, meaning individual characters can be changed.

c. Strings must be enclosed in either single or double quotes, not triple quotes.

d. Strings are iterable and can be indexed or sliced.

Option d – Strings are iterable and can be indexed or sliced.

What will "abc def".split() return in Python?

a. [‘abc’, ‘def’]

b. [‘abc def’]

c. [‘abc’, ‘ ‘, ‘def’]

d. [‘abcdef’]

Option a – [‘abc’, ‘def’]

Which method can be used to check if a string contains only digits (0-9)?

a. isnumber()

b. isdigit()

c. isnumeric()

d. isn’t()

Option b – isdigit()

What will the output be for "Hello".center(10, '-')?

a. “Hello—-“

b. “—–Hello”

c. “–Hello—“

d. “Hello–“

Option a – “Hello—-“

Which method is used to capitalize the first letter of a string in Python?

a. uppercase()

b. firstupper()

c. capitalize()

d. firstletter()

Option c – capitalize()

How can you check if a string ends with a particular suffix in Python?

a. endswith()

b. ends()

c. suffixed()

Option a – endswith()

What is the result of comparing "apple" < "banana" in Python?

a. True

b. False

c. None

d. It will raise an error.

Option a – True

How do you convert a string to a list of characters in Python?

a. Using the split() method

b. Using the list() constructor

c. Using the join() method

d. Strings cannot be converted to lists in Python.

Option b – Using the list() constructor

What will be the output of replacing " World" with "Python" in the string "Hello, World!"?

a. “Hello, Python!”

b. “Hello, WorldPython!”

c. “Hello, PythonPython!”

d. “Hello, Python World!”

Option a – “Hello, Python!”

What will be the output of "Python".islower()?

a. True

b. False

c. None

d. It will raise an error

Option b – False

Which function is used to determine if a string is a valid identifier (like a variable name) in Python?

a. isidentifier()

b. isvariable()

c. valididentifier()

d. checkvariable()

Option a – isidentifier()

What is the purpose of the str.join(iterable) function in Python?

a. It splits the string into parts

b. It concatenates elements of an iterable into a single string, using the string as a separator

c. It reverses the string

d. It counts the occurrences of a substring

Option b – It concatenates elements of an iterable into a single string, using the string as a separator

What will be the result of "python".replace("p", "P", 1)?

a. “Python”

b. “Pythton”

c. “python”

d. “Ppython”

Option a – “Python”

How can you verify if a string consists only of lowercase letters in Python?

a. By using the islower() method

b. By using the islowercase() method

c. By using the lowercase() method

d. There is no built-in method for this in Python

Option a – By using the islower() method

What will be the output of "Python"[1: -1]?

a. “p”

b. “Pytho”

c. “ytho”

d. “python”

Option b – “Pytho”

Which function is used to check if a string only contains printable characters in Python?

a. isprintable()

b. isvisible()

c. isprint()

d. isvalid()

Option a – isprintable()

What is the result of " Python ".strip()?

a. “Python”

b. ” Python”

c. “Python “

d. ” Python”

Option a – “Python”

How can you find the index of a specific character or substring in a string in Python?

a. By using the locate() method

b. By using the search() method

c. By using the find() method

d. By using the index() method

Option c – By using the find() method

What will be the result of "Python".count("o")?

a. 0

b. 1

c. 2

d. 3

Option c – 2

Which of the following methods changes the original string to lowercase in Python?

a. tolower()

b. lower()

c. lowercase()

d. smallcase()

Option b – lower()

What is the output of str(3.14) in Python?

a. “3.14”

b. 3.14

c. [3.14]

d. 3.14

Option a – “3.14”

What is the result of "Hello, World!".split(" ")?

a. [“Hello, World!”]

b. [‘Hello’, ‘World!’]

c. [‘Hello,’, ‘World!’]

d. [“Hello,”, “World!”]

Option b – [‘Hello’, ‘World!’]

How can you check if a string consists only of uppercase letters in Python?

a. By using the isuppercase() method

b. By using the isupper() method

c. By using the uppercase() method

d. There is no built-in method for this in Python

Option b – By using the isupper() method

What will be the result of "apple".isnumeric()?

a. True

b. False

c. None

d. It will raise an error

Option b – False

What will be the result of the following code: "Hello, World!".lstrip("Hello, ")?

a. “Hello, World!”

b. “Hello, World! “

c. “ello, World!”

d. “World!”

Option d – “World!”

Which method in Python checks if a string consists only of decimal characters (0-9), without including any other characters?

a. Using the isnumber() method

b. Using the isdigit() method

c. Using the isdecimal() method

d. Using the isnumeric() method

Option c – Using the isdecimal() method

What does the code "Python".isprintable() return?

a. True

b. False

c. None

d. It will raise an error

Option a – True

Which function is used to check if a string contains only ASCII characters in Python?

a. isascii()

b. ascii()

c. validascii()

d. containsascii()

Option a – isascii()

What is the result of executing "python".isalpha() in Python?

a. True

b. False

c. None

d. It will raise an error

Option a – True

Which method checks if a string contains only digits (0-9) and no other characters in Python?

a. Using the isnumber() method

b. Using the isdigit() method

c. Using the isdecimal() method

d. Using the isnumeric() method

Option b – Using the isdigit() method

What will be the output of the code "Python".index("p")?

a. 0

b. 1

c. 2

d. 3

Option a – 0

How can you substitute all occurrences of a substring in a string with another substring in Python?

a. Using the replace_all() method

b. Using a loop

c. Using the replace() method with no limit argument

d. Using the str.replaceAll() method

Option c – Using the replace() method with no limit argument

What does the function "Python".isidentifier() return?

a. True

b. False

c. None

d. It will raise an error

Option a – True

Which method would you use to check if a string is made entirely of uppercase letters (A-Z) in Python?

a. Using the isupper() method

b. Using the isuppercase() method

c. Using the upper() method

d. Using the isuppercaseletter() method

Option a – Using the isupper() method

What will be the output of "Python".count("p")?

a. 0

b. 1

c. 2

d. 3

Option b – 1

How can you check if a string contains only lowercase letters (a-z) and no other characters in Python?

a. Using the islowercase() method

b. Using the islower() method

c. Using the lower() method

d. Using the islowerletter() method

Option b – Using the islower() method

What will be the result of "Python".isnumeric()?

a. True

b. False

c. None

d. It will raise an error

Option b – False

Which method is used to verify if a string is a valid Python variable name?

a. isvalididentifier()

b. isvariable()

c. isidentifier()

d. isname()

Option c – isidentifier()

What is the result of executing "Python".startswith("p")?

a. True

b. False

c. None

d. It will raise an error

Option a – True

We covered all the MCQ on Python String Methods and Functions above in this post for free so that you can practice well for the exam.

Check out the latest MCQ content by visiting our mcqtube website homepage.

Also, check out:

Join Telegram Group and Get FREE Alerts! Join Now

Join WhatsApp Group For FREE Alerts! Join Now

Hello, I am the admin of mcqtube.com website. I am a blogger and app developer. Thanks.

Leave a Comment

Floating ChatBot
Ask

Doubt?, Ask me Anything



Sticky Bottom Popup