python string manipulation

#String method str 
t1 = "michael"
print(t1.capitalize()) #The first letter is capitalized
t2 = "MicHael" #All
lowercase, casefold is stronger, you can lowercase many unknown correspondences
print(t2.casefold ())
print(t2.lower())

t3 = t1
print(t3.center(20,"=")) #Set the width and center the content 20 represents the total length, = represents the padding position character, the default is blank, Only one character can be filled
print(t3.ljust(10,'*')) #left padding
print(t3.rjust(10,"-"))#right padding


#Find the number of occurrences of the subsequence in the character
t4 = " michaelmichaelmichael"
t4.count("mi",5,10)# 5 and 10 indicate that the search starts from the first character to the end of the first character

#encode

#decode


# ends with what # t5
starts with what
="michael"
print(t5.endswith("ae",1,2))
print(t5.startswith("e"))

t6="username\tpassword\tEmail\nhan\t123123\[email protected]\nhan\t123123\[email protected]\nhan\t123123\[email protected]\nhan\t123123\[email protected]"
print (t6.expandtabs(10)) #Format


, replace the placeholder in a string with the specified value, pay attention to the curly brackets here
# t7 = 'I,am {name},gae {a}'
# print( t7)
# v7 = t7.format(name='alex',a=19)
# print(v7) #Another

way of placeholders
# t7 = 'I,am {0},gae {1}'
# print(t7)
# v7 = t7.format('alex',19)
# print(v7)


# #Format the incoming value {"name":'han',"a":19} Dictionary format pay attention to curly brackets
# t8 = 'I,am {name},gae {a}'
# print(t8)
# v8 = t8.format_map({"name":"han","a":19})
# print(v8) #Go


to find the index value, index, if you can't find it, it will report an error, but find will not pay attention to the difference
#find index also has a starting position and an ending position
# t9 = "michael"
# print(t9.find("ch"))
# print(t9.index("ae"))



# Determine if the string contains only numbers and letters
# t10 = "michael _+"
# print(t10.isalnum( ))
# t11="michael"
# print(t11.isalpha()) #Whether it is an alphabetic Chinese character #Determine whether

it is a number
# t12 = "123324"
# v12 = t12.isdecimal()#
# v13 = t12.isdigit()


t13 = "ldsag" #Judgment
is all lowercase, turn everything into lowercase
v13 = t13.islower()
v14 = t13.lower()
print(v13,v14) #Judgment
whether it is all uppercase, the following will turn all into uppercase
v15 = t13.isupper()
v16 = t13.upper()
print(v15,v16) #Remove

left or right spaces, process left and right spaces, remove spaces by default
# t14 = " alskgja "
# t14.lstrip()
# t14.rstrip ()
# t14.strip() #remove
\t \n specified characters, the lowest match
# t14 = "#alskgja "
# t14.lstrip("x") #Remove the characters specified from the left
# t14.rstrip("gj") #Remove the characters specified from the right
# t14.strip()

is not finished yet. . .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325345376&siteId=291194637