3、有如下变量,请按照要求实现每个功能。(10分) name = "\n \t Welcome to CUEB \n \t" a. 移除name变量对应值的两边的空字符,并输出移除后的内容 (2分) b. 判断移除空字符的name变量对应的值是否以"he"开头,并输出结果 (2分) c. 将移除空字符的name变量对应的值根据"o"分割,并输出结果(2分) d. 将移除空字符的name变量对应的值变大写,并输出结果(2分) e. 获取移除空字符的name的子序列,仅不包含首字符和最后一个字符,如:python则获取ytho,root则获取oo(2分)
时间: 2024-02-23 21:59:56 浏览: 16
a. 实现代码:
```
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
print(name)
```
输出结果:
```
Welcome to CUEB
```
b. 实现代码:
```
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
print(name.startswith("he"))
```
输出结果:
```
False
```
c. 实现代码:
```
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
print(name.split("o"))
```
输出结果:
```
['Welc', 'me t', ' CUEB \n\t']
```
d. 实现代码:
```
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
print(name.upper())
```
输出结果:
```
WELCOME TO CUEB
```
e. 实现代码:
```
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
print(name[1:-1])
```
输出结果:
```
elcome to CUE
```
相关问题
有如下变量,请按照要求实现每个功能。(10分) name = "\n \t Welcome to CUEB \n \t" a. 移除name变量对应值的两边的空字符,并输出移除后的内容 (2分) b. 判断移除空字符的name变量对应的值是否以"he"开头,并输出结果 (2分) c. 将移除空字符的name变量对应的值根据"o"分割,并输出结果(2分) d. 将移除空字符的name变量对应的值变大写,并输出结果(2分) e. 获取移除空字符的name的子序列,仅不包含首字符和最后一个字符,如:python则获取ytho,root则获取oo(2分)
a. 移除name变量对应值的两边的空字符,并输出移除后的内容
```python
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
print(name)
```
输出结果为:
```
Welcome to CUEB
```
b. 判断移除空字符的name变量对应的值是否以"he"开头,并输出结果
```python
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
if name.startswith('he'):
print('Yes')
else:
print('No')
```
输出结果为:
```
No
```
c. 将移除空字符的name变量对应的值根据"o"分割,并输出结果
```python
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
result = name.split('o')
print(result)
```
输出结果为:
```
['Welc', 'me t', ' CUEB']
```
d. 将移除空字符的name变量对应的值变大写,并输出结果
```python
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
result = name.upper()
print(result)
```
输出结果为:
```
WELCOME TO CUEB
```
e. 获取移除空字符的name的子序列,仅不包含首字符和最后一个字符,如:python则获取ytho,root则获取oo
```python
name = "\n \t Welcome to CUEB \n \t"
name = name.strip()
result = name[1:-1]
print(result)
```
输出结果为:
```
elcome to CUE
```
cueb的ascii码
CUEB的ASCII码是无法确定的,因为ASCII码只包含了128个字符,而CUEB是一个大学的名称,不属于ASCII码中的字符范围。ASCII码主要包含了英文字母、数字、标点符号和一些特殊字符,用于表示文本信息。如果您需要将CUEB转换为ASCII码,可以将每个字符转换为对应的ASCII码值。以下是CUEB每个字符的ASCII码值:
C - 67
U - 85
E - 69
B - 66
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)