| 123456789101112131415161718192021 |
- """
- 字符串常用操作
- Version: 0.1
- Author: 骆昊
- Date: 2018-02-27
- """
- str1 = 'hello, world!'
- print('字符串的长度是:', len(str1))
- print('单词首字母大写: ', str1.title())
- print('字符串变大写: ', str1.upper())
- # str1 = str1.upper()
- print('字符串是不是大写: ', str1.isupper())
- print('字符串是不是以hello开头: ', str1.startswith('hello'))
- print('字符串是不是以hello结尾: ', str1.endswith('hello'))
- print('字符串是不是以感叹号开头: ', str1.startswith('!'))
- print('字符串是不是一感叹号结尾: ', str1.endswith('!'))
- str2 = '- \u9a86\u660a'
- str3 = str1.title() + ' ' + str2.lower()
- print(str3)
|