Python 字符串处理
1 单引号包围的字符串中可以包含双引号,同样,双引号包围的字符串中可以包含单引号
2 三个引号包围的字符串中既可以包含单引号,也可以包含双引号
message = "Father's Day" print(message) message = 'Mother"s Day' print(message) message = '''有"双引号"也有'单引号'哦''' print(message)
3 首字母大写
message = "father's day" print(message.title())
4 全部大写
message = "Father's Day" print(message.upper())
5 全部小写
message = "Father's Day" print(message.lower())
6 拼接字符串
message = "Father's Day" print(message + " Happy" + "!")
7 制表符(\t),换行符(\n)
message = "{\n\tUser:\n\t\tname:tom\n}" print(message)
8 删除空白
message = " test. " print(message.lstrip()) print(message.rstrip()) print(message.strip())
9 转换成字符串
message = 3 print(str(message) + " years ago")