strings.py 661 B

123456789101112131415161718192021
  1. """
  2. 字符串常用操作
  3. Version: 0.1
  4. Author: 骆昊
  5. Date: 2018-02-27
  6. """
  7. str1 = 'hello, world!'
  8. print('字符串的长度是:', len(str1))
  9. print('单词首字母大写: ', str1.title())
  10. print('字符串变大写: ', str1.upper())
  11. # str1 = str1.upper()
  12. print('字符串是不是大写: ', str1.isupper())
  13. print('字符串是不是以hello开头: ', str1.startswith('hello'))
  14. print('字符串是不是以hello结尾: ', str1.endswith('hello'))
  15. print('字符串是不是以感叹号开头: ', str1.startswith('!'))
  16. print('字符串是不是一感叹号结尾: ', str1.endswith('!'))
  17. str2 = '- \u9a86\u660a'
  18. str3 = str1.title() + ' ' + str2.lower()
  19. print(str3)