Strings And It's Manipulations
Everything written inside double quotes or single quotes called string literal in python. string belongs to <class str>
. In python "hello World or 'hello World' both are same. if we write a single character inside single quotes it will be str class type. we can use string as Comments in python.
In Python 3, a string is a sequence of characters enclosed in quotation marks, either single quotes ('
) or double quotes ("
). You can use either type of quotation marks to define a string, but you must use the same type of quotation marks to close the string. Here are some examples:
Strings in Python 3 are immutable, which means that you cannot change the individual characters in a string once it has been created. However, you can create a new string that is a modified version of an existing string.
Here are some common string operations in Python 3:
Strings also support many useful methods, such as lower()
and upper()
for converting the case of the string, strip()
for removing leading and trailing whitespaces, and replace()
for replacing a substring with another string.
String Is As Array In Python
In python, there is no array but string can be use as array and we can iterate the whole string using their index. index starts with zero.
String To List
we can type cast the string to the list, all single characters will be item in list.
Strings To Tuples
Similarly as list , we can type cast the string into the tuple.
Strings Iterations And Check Substring In String
Checking substring in string