1) They can enclosed in a single quotes ( ‘...‘
) or double quotes ( "..."
) with the same result. \
can is used to escape Quotes
2) If you don ' t want characters prefaced \
is interpreted as special characters, you can use raw strings By adding an r
before the first quote
3) String literals can span multiple lines. One is using triple-quotes: """..."""
or ‘‘‘...‘‘‘
. End of lines is automatically included in the string, but it's possible to prevent the for adding a at the \
end of T He line. The following example
4) Strings can concatenated (glued together) +
with the operator, and repeated with*
5) Both or more string literals (i.e. the ones enclosed between quotes) next to all other is automatically concat Enated. This is only works with the literals though, not with variables or expressions.
6) Strings can indexed (subscripted), with the first character have index 0. There is no separate character type; A character is simply a string of size one.
7) Indices may also is negative numbers, to-start counting from the right. Note that since-0 is the same as 0, negative indices start from-1.
8) in addition to indexing, slicing is also supported. While indexing are used to obtain individual characters, slicing allows your to obtain substring. < /em> Note How the start was always included, and the end always excluded. this makes sure that s[:i] + S[i:] is always Equa l to s. Slice indices has useful defaults; an omitted first index defaults to zero, an Omitted second index defaults to the size of the string being sliced.
9) Attempting to use a index that is too large would result in an error. However, out of range slice indexes is handled gracefully when used for slicing.
Python strings cannot be Changed-they is immutable. Therefore, assigning to a indexed position in the string results in an error.
One) the built-in function len()
returns the length of a string
The above mentioned are the basic features of string, and the string itself is a class, so it has a lot of other methods, and many, the API address is as follows:
Https://docs.python.org/3/library/stdtypes.html#string-methods
Third: base type-String type