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
我希望你好也是大写的。我不知道我的代码有什么问题。
答案 0 :(得分:0)
str.capitalize()
返回字符串的副本,其第一个字符大写,其余小写。
答案 1 :(得分:0)
您永远不会设置在函数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
我为begginers编写了最简单的代码。