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 f-string syntax allows you to print both the variable name and its value for debugging purposes?

 
 
 
 

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

 
 
 
 

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

 
 
 
 

4. Guess the correct output of the following String operation

str1 = 'Welcome'
print(str1*2)
 
 

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

 
 
 
 

6. What is the purpose of a “raw string” (prefixed with r or R) in Python?

 
 
 
 

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

 
 
 
 

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

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

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

 
 
 

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

s = "Python"
print('o' in s)
print('x' not in s)
 
 
 
 

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

 
 
 
 

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

 
 
 
 

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

 
 
 
 

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

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

15. Python does not support a character type; a single character is treated as strings of length one.

 
 

16. Guess the correct output of the following code?

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

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

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

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

 
 
 
 

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

 
 
 
 

20. Select the correct output of the following String operations

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

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

 
 
 
 

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

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

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

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

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

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

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

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

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