1.String type: A finite sequence consisting of 0 or more characters
Note: In Python, double and single quotes have the same meaning and can be used to represent strings. 2. String-built functions and operatorsstrip () remove whitespace, assign value to new variable
"= a.strip ()print(b)
Split () splits the string into a list of multiple strings.
' a b c D ' = a.split ()print(b)
Len () calculates the string length
' a b c D ' Print (Len (a))
index () to find where the element is located
' a b c D ' Print (A.index ('b'))
[start:end:step] slices, getting substrings from a string
' a b c D ' Print (A[0:5:1])
3. String formatting:
string formatting is the connection, substitution, and return of a new compliant string only by the specified rule. the expression syntax for formatting strings in Python is: format_string% String_to_convert or format_string% (string_to_convert1,string_to_convert2,...)
Print ("Hello%s, age:%d" % ("Simon", 24))
formatting of the string format ()
s="Hello {0},age {1}" #{0},{1} is a placeholder s1=s.format (' Simon','the ')print(S1)
In addition to formatting, sometimes you need to adjust the format symbol display method, the auxiliary format conforms to meet these requirements.
fixed content in a formatted string can contain
non-displayed characters in addition to characters that can be displayed , such as letters, numbers, punctuation, and so on. This character is called an
escape character . Disables the escape character with ' R '.
4. String connection join ()
Li = ["a""b""_". Join (LI)print(L1)
5. String separator spilt () and partition ()
difference: Split () passed in parameters, disappeared after segmentation, output as a listpartition () The parameters passed in, the partition exists, the output is a tupleSplitlines () split with newline (\ n) characters
' AXBCD ' = a.partition ('x' = A.split ('x') Print(b) #(' A ', ' X ', ' BCD ')print(d) # [' A ', ' BCD ']
6.id () View the memory address of a string or number
' Simon ' = ID (a)print(b) #2767282156912
Python Learning string