在我的点之后为什么不把这个词大写?

After my dot why is it not capitalizing the word?

class Capitalize:

    def __init__(self, capitalize):
        self.capitalize = capitalize.capitalize()
        #self.capitalize_dot =
        def cap():
            list =  self.capitalize.split('.')
            list[item[1].capitalize]


name = Capitalize('simon.hello')
print(name.capitalize)
>>>>Simon.hello

我希望你好也大写。我看不出我的代码有什么问题。

read the fine manual:

str.capitalize()

Return a copy of the string with its first character capitalized and the rest lowercased.

您永远不会设置在函数中创建的值 cap() 也永远不会调用它!

我认为最好像在函数 cap() 中那样创建一个数组,但不使用函数,然后使用此值使用 for 并将每个单词大写,最后使用 join设置 self.capitalize

class Capitalize:
    def __init__(self, capitalize):
        # the array of words capitalized
        wordsCapitalize = []
        # the array of words that you send and convert to array using the '.'
        words = capitalize.split('.') 
        # Iterate over the array of words
        for word in words:
            # add new value to the array of words capitalized
            # word is capitalize with function capitalize()
            wordsCapitalize.append(word.capitalize())
        # set the value to self.capitalize using '.' like character to join the values of array with words capitalized
        self.capitalize = '.'.join(wordsCapitalize)

name = Capitalize('simon.hello')
print(name.capitalize)

告诉我:

Simon.Hello

我为初学者写最简单的代码