class word:
def __init__(self,text):
self.text = text
self.sub_text = text.split(" ")
def __getitem__(self,index):
if self.sub_text[index].isalpha():
return self.sub_text[index]
else:
return self.sub_text[index][:-1]
es = word("Hello,today is a great day!")
for i in es:
print(i)
#isalpha()
#two 本来想在类的函数里面进行判断,发现太冗长,逻辑还混乱,然后思考类似于装饰器的东西
def split2(i):
s = i.split(',')
print(s)
for i in es:
split(i)
#three 思考为什么输出的东西会有引号和中括号
class word:
def __init__(self,text):
self.text = text
self.sub_text = text.split(' ')
def __getitem__(self,index):
# if self.sub_text[index].isalpha():
# return self.sub_text[index]
# else:
# return self.sub_text[index][:-1]
return self.sub_text[index]
es = word("Hello,today is a great day!")
# for i in es: #返回的是列表的每个元素,所以没有引号和中括号。
# print(i)
#isalpha()
#two
def split2(i): #返回的是一个列表
s = i.split(',')
# print(s)
for i in s:
if i.isalpha():
print(i)
else:
print(i[:-1])
print("********")
for i in es:
split2(i)
注:升华,变成取段落里的字母(oo = word("hi, you are a man!Right?")) ,提示,用elif对各种符合进行判断,冒号,引号,问号,感叹号,句号等