Strings in Python

2 min read

Text Manipulation

Today, in a lot of computations we have to deal with text. For example, whenever we prepare a document like a report, business presentation etc., we are manipulating text, searching for something or replacing and so on. We use text documents for import/export for manipulation of data.
Also, most of us manipulate queries when searching for something on the internet.
The ease of manipulating text is one of the reasons for the popularity of python.

Python uses an important sequence for text, i.e. Strings (class ‘str’).

What are the Strings?

In simple words, strings are a consecutive sequence of characters enclosed (or surrounded) by a single (‘ ‘), double (” “) or triple (‘” “‘) quotes.
A sequence of characters may include numbers, letters and special characters.

Creating/Declaring String

Double quotes and single quotes are the same in python.

String declaration.

Key points:-

String Manipulation
  • It is important to note that python does not support a character type. They are treated as strings of length one.
  • Triple quotes are used for strings that span multiple lines. They are used when we have to process a file generally.
  • Python treats quotes as special characters. To use them either we have to enclose the string in a different type of quote or to use an escape sequence (‘\’ )character indicate the special nature of a character.
  • We can also use (‘\t’) to tabulate the output.
Choose your Reaction!
Leave a Comment