|
在python3.6下执行通过:- print('abc' in 'abcde') #结果是True
- print('abc' in 'abde') #结果是False
- print(len('python')) #结果是6
- print(len('中华人民共和国')) #结果是7
- print(chr(65)) #结果是字符A
- print(chr(66)) #结果是字符B
- print(chr(20013))#输出对应的unicode字符,结果是汉字'中'
- print(ord('中')) #Unicode编码,输出是20013
- print(hex(10)) #返回16进制的值,输出是0xa
- print("Python".lower()) #返回小写,输出是python
- print("Python".upper()) #返回大写,输出是PYTHON
- a="Python is an excellent language"
- print(a.split('an')) #结果['Python is ', ' excellent l', 'guage'],按an分割
- print(a.count('a')) #结果3,统计a的次数
- print(a.count(' ')) #结果4,统计空格的次数
- print(a.count('')) #结果32,统计字符串长度
- print(a.replace('an','very')) #结果Python is very excellent lveryguage,替换
- print(a.center(50,"=")) #结果=========Python is an excellent language==========
- print(a.center(2,"=")) #结果Python is an excellent language
- b=" Hello World! "
- print(b.strip()) #结果Hello World!
- print(b.lstrip()) #结果Hello World! (右边3个空格保留)
- print(b.rstrip()) #结果 Hello World!(左边3个空格保留)
- print(b.strip("ld! ")) #结果Hello Wor。删除左右两侧以ld!开头或结尾的字符
- c="Python"
- print(c[0]) #字符串的切片。
- e=['1','2','3','4','5']
- print(','.join(c)) # 结果P,y,t,h,o,n。以逗号为分隔符重新分隔字符串
- print(','.join(e)) # 结果1,2,3,4,5。以逗号为分隔符重新分隔列表中的字符串
复制代码 |
|