PYnative

Python Programming

  • Learn Python ▼
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises ▼
    • Python Exercises
    • C++ Exercises
    • C Programming Exercises
    • Java Exercises
    • C# Exercises
  • Quizzes
  • Online Compilers▼
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
    • Online Java Compiler
    • Online C# Compiler
Home » Python » Quizzes » Python String Quiz

Python String Quiz

Updated on: August 26, 2025 | 29 Comments

This Python String Quiz provides Multiple Choice Questions (MCQs) to help you get familiar with Python Strings. To perform any programming tasks in Python, a good understanding of string manipulation is necessary. This online quiz focuses on testing your skills in Python String manipulation.

You’ll encounter questions covering:

  • String Creation and Basics: How to define strings, basic properties like length, and immutability.
  • String Indexing and Slicing: Accessing specific characters or substrings using indices and slicing techniques.
  • String Methods: Utilizing built-in string methods for common operations like changing case, searching, replacing, splitting, and joining strings.
  • String Formatting: Different ways to embed variables and expressions within strings.
  • Escape Sequences: Understanding special characters within strings.

Also, See:

  • Python String Exercise
  • 15 Python Quizzes: each focusing on a specific topic
  • The quiz contains 25 questions. There is no time limit.
  • Explanation is provided for each answer.
  • You will get 1 point for each correct answer. Solve 15 correctly to pass the test

1. What will be the output of the following Python code?

str1 = "PYnative"
print(str1[0:-1])
print(str1[:-1])
 
 
 
 

2. Which string method converts all characters in a string to uppercase?

 
 
 
 

3. Strings are immutable in Python, which means a string cannot be modified.

 
 

4. Choose the correct function to get the character from ASCII number

 
 
 

5. Which of the following is the most efficient way to concatenate a large number of small strings in a loop?

 
 
 
 

6. Select the correct output of the following String operations

str = "my name is James bond";
print (str.capitalize())
 
 
 

7. Which method is correct to convert String "welcome to python" to "Welcome To Python"

 
 

8. How would you replace all occurrences of “apple” with “orange” in the string s = "I like apple pie, apple juice."?

 
 
 
 

9. What will be the output of the following Python code?

sentence = "Joy Joy Joy"
sentence.replace("Joy", "Bliss", 2)
print(sentence)
 
 
 
 

10. Which of the following is the modern (Python 3+) and generally preferred way to format strings, offering better readability and performance than % formatting?

 
 
 
 

11. What will be the output of the following string operations

str = "My salary is 7000";
print(str.isalnum())
 
 

12. What will be the output of the following code?

str1 = "My salary is 7000";
str2 = "7000"

print(str1.isdigit())
print(str2.isdigit())
 
 
 

13. What will be the output of the following Python code?

strOne = str("pynative")
strTwo = "pynative"
print(strOne == strTwo)
print(strOne is strTwo)
 
 
 
 

14. What is the default encoding used for strings in Python 3?

 
 
 
 

15. What will be the output of the following Python code?

text1 = "Python3"
text2 = "HelloWorld"
print(text1.isalnum())
print(text2.isalpha())
 
 
 
 

16. Guess the correct output of the following code?

str1 = "PYnative"
print(str1[1:4])
print(str1[4:])
 
 
 

17. What is the difference between str.strip() and str.lstrip()?

 
 
 
 

18. What will be the output of the following Python code?

text = "abracadabra"
print(text.find('a'))
print(text.rfind('a'))
 
 
 
 

19. What will be the output of the following Python code?

myString = "pynative"
stringList = ["abc", "pynative", "xyz"]

print(stringList[1] == myString)
print(stringList[1] is myString)
 
 

20. Which string method returns True if all characters in the string are alphabetic (letters) and there is at least one character?

 
 
 
 

21. Select the correct output of the following String operations

str1 = "my isname isis jameis isis bond"; 
sub = "is"; 
print(str1.count(sub, 4))
 
 
 

22. What will be the output of the following string operation?

str1 = 'Welcome'
print (str1[:6] + ' PYnative')
 
 
 
 

23. What will be the output of the following Python code?

word = "level"
print(word == word[::-1])
 
 
 
 

24. What will be the output of the following Python code?

data = "item1,item2,item3"
parts = data.split(',')
print(parts[1])
 
 
 
 

25. What will be the output of the following Python code?

path = "/usr/local/bin/python"
print(path.split('/'))
 
 
 
 

Loading ... Loading …

Loading

Filed Under: Python, Python Basics, Python Quizzes

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Basics Python Quizzes

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises
Java Exercises
C# Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes

Comments

  1. Kowshik says

    September 15, 2026 at 11:23 pm

    Awesome Learning Website

    Reply
  2. KAUSHIK MITRA says

    August 14, 2026 at 12:48 pm

    how can I know my score in quize ? i all ready perticipate in 2 quizes , after submitting the answers i can not able to see my score , please help me Sir

    Reply
    • Bhargavi D says

      August 16, 2026 at 5:27 pm

      similar issue I am also facing. After multiple attempts I am unable to see the results. Pls guide us…

      Reply
      • Vishal says

        September 1, 2026 at 4:45 pm

        The problem has been resolved. Sorry for the inconvenience.

        Reply
  3. KAUSHIK MITRA says

    August 14, 2026 at 12:48 pm

    how can I know my score in quize ? i all ready perticipate in 2 quizes , after submitting the answers i can not able to see my score , please help me Sir

    Reply
  4. baptiste TINEL says

    May 14, 2025 at 6:37 pm

    myString = “pynative”
    myString_ = “pynative”
    ##stringList = [“abc”, “pynative”, “xyz”]
    stringList = [“abc”, myString_, “xyz”]
    print(stringList[1] == myString)
    print(stringList[1] is myString)
    print(“id(stringList[1]),id(myString)”,id(stringList[1]),id(myString))
    print(“id(stringList[1])==id(myString)”,id(stringList[1])==id(myString))

    # # True
    # # True
    # # id(stringList[1]),id(myString) 4301687006784 4301687006784
    # # id(stringList[1])==id(myString) True

    Reply
  5. av says

    December 26, 2024 at 9:49 pm

    its nice

    Reply
  6. PyFan says

    December 20, 2024 at 4:40 am

    Thanks for the quizzes. Here’s a suggested fix.

    ord(‘char’)

    should be

    ord(‘c’)

    or

    ord(‘char'[:1])

    The reason is that ord() is the right function to get the ASCII code of a character, but ‘char’ is a bad argument for it, since ord() expects a string of length 1.

    Reply
  7. J says

    July 18, 2024 at 8:43 pm

    Thanks for creating the exercise and adding the explanations!

    As a beginner, I found it challenging.

    Reply
    • osman says

      October 26, 2024 at 10:29 pm

      yes i am also beginner but it was a fun for me that a good teacher meet me on youtube and he teach it in very easy way and i didn’t find it difficult

      Reply
  8. N says

    January 2, 2024 at 4:29 am

    The answer is correct but please expand explanation for q1.

    Although it should be “True, False” because intuition will tell you that both object should be at different memory location. Some edge case where program is small python will optimize code to save myString and stringList[1] to same memory location. Despite being initialized differently.

    Reply
  9. Azmat says

    July 25, 2022 at 11:33 pm

    Sir Question No.8 sajhme nhi aa rha h syad question me mistake h ya hume samjh me nhi aaya . APP explain kr dijiye plz

    Reply
    • Rinkey Pal says

      April 9, 2023 at 6:58 pm

      In ques 8 both are pointing to word pynative, though pynative is in a list in stringList

      Reply
  10. jeevan says

    May 20, 2022 at 11:18 pm

    please explain Q 14

    Reply
    • nidhi says

      May 26, 2022 at 3:15 pm

      the isalnum() method returns true if all characters in the string are either number or alphabets..thus space is not one’em sot he answer is False

      Reply
    • m-fazin says

      August 16, 2022 at 7:21 am

      that code is checking in a string is it fully digits or none

      Reply
    • Rinkey Pal says

      April 9, 2023 at 7:00 pm

      title() make every first letter capital and capitalize() make only first letter of sentence capital.

      Reply
  11. hexsoNNN says

    November 23, 2020 at 7:10 pm

    Few remarks : adding the date for comments would really be helpful to know if the code is still up-to-date
    And some questions are still missing a bit of description!
    Really cool test, thanks! Your exercices on python strings were really helpful aswell.

    Reply
  12. ruchir says

    October 27, 2020 at 5:30 pm

    can you plz add a collumm in which we add our code and it by executing explains us error in that box
    eg – print(str1[3:], “and ”, str1[:2])

    Reply
  13. Shayeri says

    August 17, 2020 at 12:55 pm

    Very helpful site, but explanations for certain answers are not provided.

    Reply
    • Vishal says

      August 19, 2020 at 11:46 am

      Hey Shayeri, I will add that

      Reply
  14. Giorgio Incantawolf says

    June 21, 2020 at 7:45 pm

    Hello, Q11 should have “Welcome To The Beautiful World Of Python” as result not “Welcome To The Beautiful World of Python”. All the world are capitalized, even of

    Reply
    • Giorgio Incantawolf says

      June 21, 2020 at 7:48 pm

      Sorry, it is Q4, not Q11

      Reply
      • Giorgio Incantawolf says

        June 21, 2020 at 7:51 pm

        Hi, it is Q12 now…. ok they are randomly generated 🙂
        By the way, the issue is that one I reported 🙂
        Thank you
        P.S.: really good site, that’s why I’m reporting issues 😉

        Reply
        • Vishal says

          June 22, 2020 at 8:01 pm

          Hey Giorgio, I have updated the reported question. I really appreciate your time and effort in letting me know the suggestions.

          Reply
    • Vishal says

      June 22, 2020 at 8:02 pm

      Hey Giorgio, I have updated the question. Thank you.

      Reply
  15. Rohan says

    February 28, 2020 at 2:11 pm

    For Q12, I am getting 6 as answer.

    Reply
    • Vishal says

      March 1, 2020 at 12:35 pm

      Thanks for informing me. I have updated the correct answer now.

      Reply
    • JAYESH says

      June 17, 2020 at 10:44 am

      Q.13

      Reply

Leave a Reply Cancel reply

your email address will NOT be published. all comments are moderated according to our comment policy.

Use <pre> tag for posting code. E.g. <pre> Your entire code </pre>

In: Python Python Basics Python Quizzes
TweetF  sharein  shareP  Pin

  Python Quizzes

  • 15 Python Quizzes
  • Python Online MCQ Test
  • Basic Quiz For Beginners
  • Variables and Data Types Quiz
  • Functions Quiz
  • if else and loops Quiz
  • Numbers Quiz
  • String Quiz
  • List Quiz
  • Set Quiz
  • Dictionary Quiz
  • Tuple Quiz
  • Operators and Expression Quiz
  • Input and Output Quiz
  • Multithreading and Multiprocessing Quiz
  • File Handling Quiz
  • Random Data Generation Quiz

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

Python Basics Python Exercises Python Quizzes Python Interview Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

About PYnative

PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises
  • Java Exercises
  • C# Exercises

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2026 pynative.com