s = str(input ()) S2 = s.lower S3 = S.upper S4 = S.capitalize print (f"{s2}") print(f" {s3}") print (f" {s4}") 打印出来的是地址?
时间: 2024-01-22 18:19:56 浏览: 22
是的,因为在代码中,对字符串的转换操作没有使用括号,正确的写法应该是 `s.lower()`、`s.upper()`、`s.capitalize()`。修改后的代码如下:
```
s = str(input())
s2 = s.lower()
s3 = s.upper()
s4 = s.capitalize()
print(f"{s2}")
print(f"{s3}")
print(f"{s4}")
```
这样就能够正确地将字符串转换为小写字母、大写字母和首字母大写,并打印输出它们的值了。
相关问题
s = "python is an excellent language",字符串首字母大写
。你能帮我用 Python 改为首字母大写的字符串吗?
当然可以,下面是 Python 代码:
s = "python is an excellent language"
s = s.capitalize()
print(s)
输出结果为:
Python is an excellent language
str.capitalize
str.capitalize() 是 Python 中字符串方法之一,它可以将字符串的第一个字符转换为大写,其余字符转换为小写。例如:
"hello world".capitalize()
# 输出 "Hello world"
"HELLO WORLD".capitalize()
# 输出 "Hello world"
"123abc".capitalize()
# 输出 "123abc"
第一个字符必须是字母才能转换。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)