用Python将一句英文里的每一个单词首字母大写
时间: 2023-05-24 07:04:08 浏览: 206
A:
可以使用 Python 内置的 `title()` 方法将一句英文里的每一个单词首字母大写,例如:
```python
s = "this is a sentence."
s_title = s.title()
print(s_title)
# This Is A Sentence.
```
其中,`s` 是原始字符串,`s_title` 是将 `s` 中的每一个单词的首字母大写后得到的新字符串。可以通过 `print()` 函数输出 `s_title` 来查看结果。
相关问题
用Python中的split()将一句英文里的每一个单词首字母大写
A:
```python
sentence = "hello world, welcome to CSDN"
words = sentence.split()
new_sentence = " ".join([word.capitalize() for word in words])
print(new_sentence)
```
输出:
```
Hello World, Welcome To Csdn
```
用puthon语言输入一句英文,将每个单词的首字母转换为大写。
可以使用 Python 的 title() 方法将每个单词的首字母转为大写。示例如下:
```
sentence = input("请输入英文句子:")
result = sentence.title()
print(result)
```
输入:`this is a sentence.`
输出:`This Is A Sentence.`