建立類:python
class MyString():
初始化賦值:數據結構
# def __init__(self,engishstr): # self.mystr = engishstr
簡單的一個面向對象實列:ide
# def show_counts(self): # len_word = len(self.mystr) # print(len_word) # def show_char_counts(self): # word = self.mystr # len_word = len(self.mystr) # word_count = word.count(" ") # print(len_word - word_count) # def show_cap(self): # word = self.mystr # word_upper = word.upper() # print(word_upper) # def show_word_counts(self): # word = self.mystr # word_split = word.split(" ") # len_word = len(word_split) # print(len_word) # def show_last_word_len(self): # word = self.mystr # word_split = word.split(" ") # word_len = len(word_split[-1]) # print(word_len) # def show_long_word(self): # word = self.mystr # word_split = word.split(" ") # max_word = word_split[0] # for x in word_split: # if len(x)>len(max_word): # max_word = x # print("最長單詞爲%s,長度位%d" % (max_word,len(max_word)))