Connect lesson, str method
isPrintable () whether there is a non-displayable character, \ t, \ n, false output
isspace, to determine whether the whole space
istitle, to determine whether the title, the first letter capitalized,
title, is set to headline
test = " hearewa \ tdsjdsdjs \ ndd \ TSSD \ t " v = test.expandtabs (6 ) print (v) # 结果 # hearewa dsjdsdjs # dd ssd
= Test " two " # decimal fractional, commonly V1 = test.isdecimal () # including 2, ② V2 = test.isdigit () # including 2, ②, two Chinese V3 = test.isnumeric () Print (V1, V2 , v3) # result # False False True
# String in each element specified delimiter stitching the Test = " You are the wind I am the sand " Print (the Test) t = " " # v = "" .join (the Test) v = t.join ( the Test) Print (v) # result # you are the wind I am the sand # you are the wind I am the sand
#filling
test="alex" v1=test.ljust(6,"*") v2=test.rjust(6,"*") print(v1,v2) # 结果 # alex** **alex
= the Test " alex " test.islower () # if all lowercase test.lower () # lowercase test.isupper () # if all uppercase test.upper () # capitalize
# Removed blank, removing \ n, \ t, removes the specified character Test = " aleaax " # test.lstrip () V = test.rstrip ( ' AX ' ) # test.strip () Print (V) # Results # ALE
# 分割 test="testdsdsg" v1=test.partition('s') v2=test.rpartition('s') v3=test.split('s') v4=test.split('s',2) print(v1,v2,v3,v4) # 结果 # ('te', 's', 'tdsdsg') ('testdsd', 's', 'g') ['te', 'td', 'd', 'g'] ['te', 'td', 'dsg']
# There is a regular expression, select whether to include the selected character segmentation # segmentation, segmentation according newline Test = " TESTD \ NSDS \ ng " V1 = test.splitlines (False) V2 = test.splitlines (True) Print (V1, V2) # results # [ 'TESTD', 'SDS', 'G'] [ 'TESTD \ n-', 'SDS \ n-', 'G']
# Whether what beginning v1 = test.startswith ( ' A ' ) v2 = test.endswith ( ' G ' ) Print (v1, v2) # result # False True
# Case conversion Test = " asfsdgHkk " V1 = test.swapcase () Print (V1) # Results # ASFSDGhKK