String in Python Class 11 Notes
String Data Type in python
WHAT ARE STRINGS?
In Python, a consecutive sequence of characters, which are enclosed or surrounded by single (”) or double (““) quotes, is known as a string. This sequence of characters may include a letter, a number, special character or a backslash.
A string may be specified by placing the member characters of the sequence within quotes (single, double or triple). Python treats single quotes the same as double quotes.
Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end.
The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator. For example −
Strings are amongst the most popular data types in Python. We can create them by simply enclosing characters in quotes (single, double or triple). Python treats single quotes the same as double quotes. Sometimes triple quotes can be used in Python but they are generally used to represent multiline strings and doc strings. An empty string is a string that has 0 character. Creating strings is as simple as assigning a value to a variable.