One, the string
In Python, a string is an important data type. Other data types are:
- The number-number-------- int, long, float, complex
- String-string-------- "Use quotation marks" are quoted as strings.
- Tuple-tuple------------elements enclosed in parentheses, separated by commas
The above three is the immutable object in Python, the amount that cannot be changed after creation--the value that the variable points to memory cannot be changed, when a variable is changed, because its value cannot be changed, it is equivalent to copy the original value and then change, this will open a new address, The variable points to this new address again.
- List-list--------------- [1, 2, 3] [' A ', ' B ', ' C '] brackets, the elements inside are separated by commas
- Dictionary-dict-------------- {key1:value1, key2:value2} use curly braces + key-value method definitions, use between key values: colon, separate key pair values using commas
- Boolean-bool--------- true and False
4, 5, 6 are mutable objects, meaning that the object points to the memory value can be changed.
1.1 Method of String
str.capitalize()
Will capitalize the first letter
str.count(x, start=None, end=None)
Counts the number of characters x specified in str, start and end as start and ending bits
str.center(num, [指定字符])
The STR string is centered in the num-length character and the second parameter is the padding character if the Str is not long enough. "{0:[填充字符]^[长度]}".format(str)
the same effect
str.endswith("tr")
Determines if STR is a specified parameter, and here is the end of "TR", which returns True no false
str.find([指定字符])
Find the starting index of the parameter character in Str
str.isalnum()
Whether STR is an Arabic numeral, a character, is a return true
str.isalpha()
Is it pure English?
str.isdecimal()
is a decimal number
str.isdigit()
is an integer
str.isidentifier()
is a valid identifier (variable name)
str.islower()
Whether the string is all lowercase
str.lower()
Lowercase the string
str.isupper()
Whether the string is uppercase
str.upper()
Capitalize a string
‘[分隔符]‘.join([iterable])
"+".join([‘1‘, ‘2‘, ‘3‘])
the Join method argument as the result of the ' 1+2+3 ' delimiter is a recyclable object
str.ljust(num, ‘[填充符]‘)
Extended str length to num, not enough position to fill from right to left with padding
str.split(sep=None)
Splits a character by the Sep parameter and returns the split element as a list
str.strip(chars=None)
important The default is to remove space, \ n, \ t, or remove the specified parameter number from the string header and tail
>>> str_test = ‘\n/home/user/lina
String, dictionary manipulation methods in Python