A list of strings and built-in method

Sequence type (Sequence Types)

Sequence type comprising: list, tuple, range, added: string type, the type of binary data (binary data)
which comprises a variable sequence types: such as List, immutable sequence types: type such as string, tuple type

Variable sequence type operation

1. List

Consensus sequence type operation: index value, the index slices, values ​​for loop, operation member, index lookup index position, len length, '+' operator

Add elements: append, expand, insert

Remove elements: pop, del, remove, clear

Your search: sort, reverse

lst = [0 for i in range(10)]
lst
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
lst[:5] = range(1,6)
lst
[1, 2, 3, 4, 5, 0, 0, 0, 0, 0]
lst *= 2
lst
[1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0]
lst.pop(0)
lst
[2, 3, 4, 5, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0]
[func for func in dir(lst) if not func.startswith("__")]
['append',
 'clear',
 'copy',
 'count',
 'extend',
 'index',
 'insert',
 'pop',
 'remove',
 'reverse',
 'sort']

Immutable sequence type operation

String

[func for func in dir("str") if not func.startswith("__")]
['capitalize',
 'casefold',
 'center',
 'count',
 'encode',
 'endswith',
 'expandtabs',
 'find',
 'format',
 'format_map',
 'index',
 'isalnum',
 'isalpha',
 'isascii',
 'isdecimal',
 'isdigit',
 'isidentifier',
 'islower',
 'isnumeric',
 'isprintable',
 'isspace',
 'istitle',
 'isupper',
 'join',
 'ljust',
 'lower',
 'lstrip',
 'maketrans',
 'partition',
 'replace',
 'rfind',
 'rindex',
 'rjust',
 'rpartition',
 'rsplit',
 'rstrip',
 'split',
 'splitlines',
 'startswith',
 'strip',
 'swapcase',
 'title',
 'translate',
 'upper',
 'zfill']

Consensus sequence type operation: index value, the index slices, values ​​for loop, operation member, index lookup index position, len length, '+' operator

Shorten characters: strip, lstrip, rstrip

Add character: center, ljust, rjust, zfill

Cutting and connecting: split (rsplit), join, splitlines

Conversion or alternatively: upper, lower, swapcase, title, capitalize, replace, translate

判断:isdigit, isalpha, startswith, endswith ...

Guess you like

Origin www.cnblogs.com/YajunRan/p/11521941.html