在Python中,可以使用`title()`方法将一个英文句子中的每个单词的首字母由小写转换为大写。下面是一个例子:
```python
s = 'hello world'
s_title = s.title()
print(s_title) 输出: Hello World
```
在这个例子中,`title()`方法将字符串`'hello world'`中的每个单词的首字母转换为大写,得到`'Hello World'`。
如果你想要将每个单词的首字母由小写转换为大写,同时保持其他字母不变,可以使用正则表达式和`sub()`方法,像这样:
```python
import re
s = 'hello world'
s_title = re.sub(r"\w+", lambda match: match.group(0).capitalize(), s)
print(s_title) 输出: Hello World
```
在这个例子中,`re.sub()`方法使用一个lambda函数来将每个匹配的单词(由`\w+`正则表达式匹配)的首字母转换为大写,其他字母保持不变。