The name str in Python is used to denote strings. This is a built-in data type that is an ordered sequence of Unicode characters. Typically, strings contain textual information. They are similar to C language arrays, but have a number of powerful processing tools.
Line literals
There are several ways to write strings. The most popular are quotation marks and apostrophes. They are interchangeable and their use allows to exclude the backslash character "\":
- >>> Example_1 = "This is how the lines are written"
When processing strings in Python, triple quotes are also allowed. It is convenient to enclose large blocks of text in them. Inside the design, apostrophes and ordinary quotation marks may be present:
- >>> Example_2 = "" "An approximate set of words for the" block line "in Python" "»
Basic operations
. , , , :
- >>>_1 = «FB» #
- >>>_1
- «FB»
- >>>_2 = _1 + «.» + «ru» #
- >>>_2
- «FB.ru»
- >>>_3 = «O» * 3 + «PS!» #
- >>>_3
- «OOOPS!»
- >>>len(_3) #
- 6
Python str , .
. , . . , « »[1]:
«:» . , . , , , :
Python str() . . , , «+» . :
- >>>5+ «dogs» + «run»
- Traceback (most recent call last): … TypeError
- >>>str(5) + « dogs » + « run.»
- «5 dogs run.»
str() repr(). , .
. – , , .
: «.()».
- >>>l= «ggffkkllrr»
- >>>l.replace(«ff», «gg»)
- «ggggkkllrr»
.replace(). .
, . .