Python 语法(一)

字符串操作

使字母改为大写

name = "hello python"
name = name.upper() 
print(name)   # 输出为HELLO PYTHON

使字母改为小写

name = "HELLO PYTHON"
name = name.lower()
print(name)    # 输出为 hello python

使首字母大写

name = "hello pyton"
name = name.title()
print(name)    # 输出为 Hello Python

去除空格字符

name = " hello python "
name = name.strip()
print(name)    # 输出为 "hello python"  会去掉两端的空格 而两个单词中间的不会去

你可能感兴趣的