这是一个笔记
str1 = 'nottin.soulrn.orlog.iduna' #字符串是不可变类型。
def mark_out_index(): #姑且称其为字符串的遍历好了
a = len(str1)
for i in str1:
print(i,end=' ')
print('')
for j in range(0,a):
print('%02d' %j,end=' ')
print('')
def return_values(): #all these functions below returns a value.
a = str1[23] #[index],to pick out specific character
b = str1[::] #[start:over:step]
c = str1.rfind('s') #('str'),"rfind" or "find"
e = str1.rindex('o') #('str'),"rindex" or "index"
g = str1.count('.',4) #('str', times),default counts all
d = str1.replace('.', ',',5)#('origin_str', 'new_str', times),default replaces all
f = str1.split('.',5) #('str', times),default splits all and returns a list
h = '@'.join(f) # 'str'.join(list) ,use 'str' to connect all elements in list and returns a new str
i = str1.title() #changes every element's initial letter to CAP
j = str1.capitalize() #changes first character to CAP,and doesn't work if str starts with a space
k = str1.upper() #changes every letter to CAP
l = str1.lower() #changes every letter to lower
m = str1.strip() #remove spaces of both sides,"lstrip" for starts_side and "rstrip" for ends_side
n = str1.center(29,'.') #(num,'str')center the original str and add 'str' to reach 'num' characters
o = str1.ljust(29,'.') #(num,'str')left align and same with above.
p = str1.rjust(29,'.') #no need to say
q = str1.startswith('nott') #('str'),check if str1 starts with ('str') and return bool type
r = str1.endswith('iduna') #('str'),check if str1 ends with ('str') and return bool type
s = str1.isalpha() #judge if str is not empty and composed with letter and return bool type
t = str1.isdigit() #judge if str is not empty and composed with integer and return bool type
u = str1.isalnum() #judge if str is not empty and composed with integer/letter and return bool type
v = str1.isspace() #judge if str is empty and return bool type
ww = s #change var_name to print
print(ww)
mark_out_index()
return_values()
希望能够得到补充或者建议。
另外我这个键盘键程比较长,有的时候虽然按下去了但是并没有触发按键