一、大小写转换
- 首字母大写
title() - 全部大写
upper() - 全部小写
lower()
name = "tim peters"
# 首字母大写
print name.title()
# 全部大写
print name.upper()
# 全部小写
print name.lower()

image.png
二、剔除字符串两端的空白
- 剔除两端的空白
strip() - 剔除开始(左边)的空白
lstrip() - 剔除结束(右边)的空白
rstrip()
为了查看方便,我使用了repr()函数。
str = " Hello Python! "
print repr(str)
# 剔除两端的空白
print repr(str.strip())
# 剔除开始(左边)的空白
print repr(str.lstrip())
# 剔除结束(右边)的空白
print repr(str.rstrip())

image.png
后续的字符串操作持续更新中。。。