Strings:
A string is a data type in Python. A string is a sequence of characters enclosed in quotes. If we have to write a string, we can use it in these three ways.
a = 'hammad' ➡️ Single quoted string
a = "hammad" ➡️ Double quoted string
a = '''hammad''' ➡️ Triple quoted string
String Slicing:
A string in Python can be sliced to get a part of the string.
Let's say we write a program like name = "hammad". Now, if we have to slice the string, we use .len()
"hammad"
Positve index = 0123456
Negative index = -6 -5-4-3-2-1
Note:
Positive index are start from 0 (Left to right)
Negative index are start from -1 (Right to left)
The index in a string starts from 0 to (length -1) in Python. In order to slice a string, we use the following syntex.
s = name[start : end]
first index is included, and the last index is not included.
Escape Sequence Characters:
Sequence of characters after backslash "\" are called Escape Sequence characters.
These characters represent one special character inside strings.
For example:
\n for new line
\t for tab space
\\ for backslash
\' for single quote
etc