考试报名
考试报名
考试内容
考试大纲
在线客服
返回顶部

备考刷题,请到

CDA认证小程序

字符串中使字符全部变为大写形式的方法是?
A. split()
B. strip()
C. lower()
D. upper()
上一题
下一题
收藏
点赞
评论
题目解析
题目评论(0)

正确答案是:D: `upper()`

### 专业分析:

在 Python 中,处理字符串时有多个内建方法,每个方法都有特定的功能:

1. **split()**:
- 功能:用于将字符串按照指定分隔符进行拆分,返回一个列表。
- 示例:

```python
text = "hello world"
result = text.split()
# result: ['hello', 'world']
```

2. **strip()**:
- 功能:用于移除字符串开头和结尾的空白字符(如空格、换行符)。
- 示例:

```python
text = " hello world "
result = text.strip()
# result: 'hello world'
```

3. **lower()**:
- 功能:用于将字符串中的所有字母字符转换为小写。
- 示例:

```python
text = "Hello World"
result = text.lower()
# result: 'hello world'
```

4. **upper()**:
- 功能:用于将字符串中的所有字母字符转换为大写。
- 示例:

```python
text = "Hello World"
result = text.upper()
# result: 'HELLO WORLD'
```

### 总结:

在给定选项中,只有 `upper()` 方法能够将字符串中的所有字符转换为大写形式,因此正确答案是 D: `upper()`。