我想编写一个简单的程序,如果用户输入一个句子,程序会自动将其转换为camelcase。这是我到目前为止所做的。
import re
sentence=str(input("enter sentence: ")
print (sentence)
def convert (name):
s1=re.sub('(.)(a-z[A-Z]+)',r'\1_\2',name)
return re.sub('([a-z0-9])([A-Z])',r'\1_\2',S1).total()
任何帮助都会很棒。
答案 0 :(得分:1)
使用title
方法。
>>> sentence = input("Enter sentence: ")
Enter sentence: ive got a lovely bunch of coconuts
>>> sentence = sentence.title()
>>> print(sentence)
Ive Got A Lovely Bunch Of Coconuts