用Python将一句英文里的每一个单词首字母大写
时间: 2023-05-24 08:04:08 浏览: 329
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
```
用python编写一个程序 将“very imporant person"这句话中每个单词的首字母大写提取出来组成一个新的单词
可以使用Python中的字符串操作来提取出每个单词的首字母并将其组合起来。
以下是一个可能的实现:
```
string = "very important person"
words = string.split() # 将字符串分割成单词列表
acronym = ""
for word in words:
acronym += word[0].upper() # 获取每个单词的首字母并转换为大写
print(acronym) # 输出组合后的首字母缩写
```
执行这段代码将会输出 "VIP",即由每个单词的首字母组成的缩写。
阅读全文
相关推荐














