print('hello'.isalpha())>>>>>Trueprint('hello123'.isalnum())>>>>>Trueprint('123'.isdecimal())>>>>>Trueprint(' '.isspace())>>>>>Trueprint('This Is Title Case 123'.istitle())>>>>>True
spam =' Hello World 'print(spam.strip())>>>>> Hello World
print(spam.lstrip())>>>>> Hello World
print(spam.rstrip())>>>>> Hello World
spam ='SpamSpamBaconSpamEggsSpamSpam'print(spam.strip('ampS'))>>>>> BaconSpamEggs
tableData =[['apples','oranges','cherries','banana'],['Alice','Bob','Carol','David'],['dogs','cats','moose','goose']]defprint_table(table):defrow_width(table2):
maxlen =0for item in table2:iflen(item)> maxlen:
maxlen =len(item)return maxlen
for i inrange(len(table[0])):for j inrange(len(table)):print(table[j][i].rjust(row_width(table[j])), end=' ')print()
print_table(tableData)>>>>> 输出:
apples Alice dogs
oranges Bob cats
cherries Carol moose
banana David goose