Section 1 – Basics of Strings in Python
String is the most important topic in Python. If you learn strings correctly, then it becomes easier to learn other advanced topics in Python.
String is a collection of characters enclosed within quotes.
Strings help you in many ways in Python. For example, if you want to store, display, and process the data type, string data type will help you in these tasks.
a) Creating StringsIf you want to create a string in Python, then you can use either single quotes (‘ ’) or double quotes (“ ”).
Example:
Both the strings written above are valid ones and work exactly the same way.
Based on your choice / need, you can choose any one of them to stay consistent in code.
b) Why Two Types of Quotes?
If your text contains single quotes, then you should use double quotes.
If your text contains double quotes, then you should use single quotes.
Example:
This will help you to avoid errors and to keep your code clean and readable.
c) Concatenating Strings Using +It is used if you want to combine two or more strings, then you can use + operator.
Example:
d) f-Strings (Modern & Best Way)
If you want to format text in Python language, then f-string is one of the most powerful and modern ways to perform it.
Example:
f-String is easy to read and is mostly used in real-world projects and technical interviews.
e) Strings Are Immutable
Immutable means once you have created a string, then you cannot change it.
If you want to change a text inside a string, then Python will not allow it (as shown below):
Example:

If you want to modify a string, then you will have to create a new one.
Example:
f) Triple-Quoted String (‘’’ ’’’ or “”” “ ” ”)If you want to write a long message, paragraphs, or documents in multiple lines, then triple quotes are used in Python.
One of the most important applications of triple-quoted strings is to write docstrings, which describe what a function does in your program.