方法

Dict
keys() values() items() #they will return the data type of dict_keys dict_values dict_items,e.g.:for k,v in dict.items():

dict.get(key,backed-value)  #return backed-value if key not exist
dict.setdefault(key,value) #key is the value looking for,value used to add a new key when key isn't exist

dict.popitem()   #take out a ky_value item randomly from dict,return a tuple including item and delete the item

dict.clear()

del dict[key]

dict.pop(key,default)dict.update(dict1)  #add key-dict items from dict1 to dict

List
index(obj[,start,end]) #return the subscript of an object,or return ValueError
list.append(obj)    #append new element in the ending of list, obj can be any data type
list.extend(seq) #extend will add all elements after the decomposition of seq
list.insert(num,obj) #obj can be any data type,after the specified subscript is inserted, each element after it moves one bit

list.pop(subscript) #Default last one
list.remove(obj)  #Delete the specified value
del seq[subscript] #similar to pop

list.sort([reverse=True]) #can't sort a list with number and string
list.reverse()  #Reverse the original order of elements

copy.copy(list)  #copy a list,import copy first
copy.deepcopy(list)  #use deepcopy when a list includes list

seq.clear() #clear all element of any type

String
upper() lower() title()
The methods of string using isX:
isupper()  
islower()
isalpha()  #return True if string only includes alpha
isalnum()  #return True if string only includes alpha and number
isdecimal()=isdigit()  #return True if string only includes number string
isspace()  #return True if string only includes space,\t,\n
#The above four are not None string
istitle()  #return True if string begin with capital,following all lowercase

string.startwith(str)
string.endswith(str) #return True if string starts or ends with str

str.join(list) #call on a string,return a string linked with the original str
string.split(str,num)[n]  #call on a string,return a list which split by str,num is the split time ,n specify which to return

string.replace(oldstr,newstr[,n])

rjust(num,str)
ljust(num,str)
center(num,str) #num is a integer impressing the length of padding character

strip()
rstrip()
lstrip()  #Delete the corresponding whitespace

pyperclip.copy(str)
pyperclip.paste(str) #import pyperclip first,copy text from or paste text to computer

string.count(str,[start,end])  #count the time of some string appear

posted @ 2022-04-08 16:30  Riveru  阅读(23)  评论(0)    收藏  举报