【Python-2.7】大小写转换函数

字母大小写是编程过程中经常遇到的问题,如下函数可以灵活的进行大小写转换:

title():把单词首字母转换为大写;

upper():把每个字母转换为大写;

lower():把每个字母转换为小写。

示例如下:

#message变量
>>> message = 'HELLO world!'
>>> print(message)
HELLO world!

#首字母大写
>>> print(message.title())
Hello World!

#全部大写
>>> print(message.upper())
HELLO WORLD!

##全部小写
>>> print(message.lower())
hello world!

  




posted on 2017-09-20 15:37  Diegoal  阅读(586)  评论(0编辑  收藏  举报

导航