类型转换: str(x)

  1. age = 23
  2. message = "Happy " + str(age) + "rd Brithady!"
  3. print(message) # Happy 23rd Brithady!

转大写: s.upper()

转小写: s.lower()

删除左空格: s.lstrip()

删除右空格: s.rstrip()

删除左右空格: s.strip()

单词首字母大写: s.title()

  1. args = "abc def"
  2. result = args.title()
  3. print(result) # Abc Def

字符串转Bytes格式:str.encode(s)

  1. args = "abcdef"
  2. result = str.encode(args)
  3. print(result) # b'abcdef'