新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

Python中字符串转换大小写的有哪些方法,Python中字符串转换为整数

发布时间:2024-04-02 18:15:01

Python中字符串转换大小写的有哪些方法

Python中字符串转换大小写的方法有三种:

  1. 使用upper()方法将字符串转换为大写。例如:
s = "hello"
s_upper = s.upper()
print(s_upper)  # 输出:HELLO
  1. 使用lower()方法将字符串转换为小写。例如:
s = "HELLO"
s_lower = s.lower()
print(s_lower)  # 输出:hello
  1. 使用title()方法将字符串中每一个单词的首字母转换为大写。例如:
s = "hello world"
s_title = s.title()
print(s_title)  # 输出:Hello World