50 Interview Questions on Python Strings

Mohsin Shaikh
6 min readJan 22, 2024
50 Interview Questions on Python Strings

Basic Concepts

1. What is a string in Python?

A string in Python is a sequence of characters. It is an immutable data type, meaning once a string is created, it cannot be modified.

2. How do you define a string in Python?

You can define a string in Python using single ('), double ("), or triple (''' or """) quotes. For example:

single_quoted = 'Hello'
double_quoted = "World"
triple_quoted = '''Python'''

3. Explain the difference between single, double, and triple quotes for defining strings.

Single and double quotes are interchangeable, but using triple quotes allows strings to span multiple lines.

4. How can you concatenate two strings in Python?

Strings can be concatenated using the + operator or by simply placing them next to each other. For example:

concatenated_string = "Hello" + " " + "World"

5. What is the difference between str() and repr()?

--

--

Mohsin Shaikh

A Data Scientist who reads data to bring valuable insights and bring Business from them.