strings_python
strings_python
Python has several data types and string among them. String represents sequence of character.
String is used for mainly for manipula ng text data in python.
There are two ways of defining the string either in single quote (‘’) or in a double quote (“ “).
Python does not have single character data type like another languages. Single character means
string of length 1.
If we look at the deeper in python the string is a class called str. You can read more on the official
documenta on on by clicking this link (h ps://docs.python.org/3/library/stdtypes.html#str).
Most of the references are taken from official documenta on of the python. You my read more
about string by clicking this link (h ps://docs.python.org/3/library/stdtypes.html#text-sequence-
type-str)
As it is already men oned that the string is a sequence data type It can also be indexed like lists
and another data type.
a = “hello there!”
print(a[0:1]); # shows the h
#The above code has a[Star ng index:ending index:jump]
* string.ascii_le ers
string.ascii_lowercase
string.digits
If sub is empty, returns the number of empty strings between characters which is the
length of the string plus one.
Return the lowest index in the string where substring sub is found within the slice
s[start:end]. Op onal arguments start and end are interpreted as in slice nota on.
Return -1 if sub is not found.
There are tons of methods defined for the string in the str class you can read them on the
official python documenta on by clicking this link
(h ps://docs.python.org/3/library/stdtypes.html#string-methods)
* Integer data can also be converted to the string using the str constructor of str class.