Linux 拨号vps windows公众号手机端

Python中字符串转换大小写的方法是什么

lewis 7年前 (2018-03-26) 阅读数 10 #程序编程
文章标签 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
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门