PYnative

Python Programming

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

Python String Quiz

Updated on: August 26, 2025 | 24 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. Which string method checks if all characters in the string are digits (0-9) and the string is not empty?

 
 
 
 

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

 
 
 
 

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

text = "programming"
print(text.count('g'))
print(text.count('m', 5))
 
 
 
 

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

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

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

5. Which string method would you use to center a string within a specified width, padding with a specified character?

 
 
 
 

6. You have a list of strings words = ["hello", "world", "python"]. How would you join them into a single string "hello-world-python"?

 
 
 
 

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

sentence = "Python Python Python"
sentence = sentence.replace("Python", "PYnative", 1)
print(sentence)
 
 
 
 

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

 
 
 
 

9. What will be the output of the following string comparison

print("John" > "Jhon")
print("Emma" < "Emm")
 
 

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

 
 

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

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

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

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

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

 
 
 
 

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

 
 
 

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

s = "Python"
print(s[2:5])
 
 
 
 

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

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

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

 
 
 
 

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

 
 
 
 

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. Select the correct output of the following String operations

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

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

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

22. Guess the correct output of the following String operation

str1 = 'Welcome'
print(str1*2)
 
 

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

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

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

 
 
 
 

25. Which string method is used to count the number of non-overlapping occurrences of a substring in the string?

 
 
 
 

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

Image

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

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

Loading comments... Please wait.

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

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

Advertisement