python学习笔记之基础操作(二)字符串操作(2)
2018-10-10 13:53
585 查看
版权声明:所有资料资源均应用作教育用途,请勿用作商业用途 https://blog.csdn.net/qq_38876114/article/details/82995937
#二:替换操作 #replace():替换指定字符串 test = "123abcefsdfa" print(test.replace("123","___"))[/code]
___abcefsdfa
#swapcase():转换大小写: test = "asdfgVBNMK" print(test.swapcase())[/code]
ASDFGvbnmk
#upper(),lower() print(test.upper()) print(test.lower())[/code]
ASDFGVBNMK asdfgvbnmk
#三,分割操作 #split():按照指定字符串分割字符,可以指定分割的数量 test = "123,456,789" print(test.split(",")) print(test.split(",",1))[/code]
['123', '456', '789'] ['123', '456,789']
#partition()按照指定字符串分割为两部分,包含分隔符 #rpartition(),右面第一个开始分割 print(test.partition(",")) print(test.rpartition(","))[/code]
('123', ',', '456,789') ('123,456', ',', '789')
#四:查找操作 #find():找不到返回-1 test = "12345672" print(test.find("2")) print(test.rfind("2")) print(test.find("a"))[/code]
1 7 -1
#index同上,不过返回错误找不到的话 print(test.index("2")) print(test.rindex("2")) print(test.index("a"))[/code]
1 7 --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-17-af7b2106d969> in <module>() 2 print(test.index("2")) 3 print(test.rindex("2")) ----> 4 print(test.index("a")) ValueError: substring not found阅读更多
相关文章推荐
- python学习笔记之基础操作(五)字符串格式化(2)format
- Python基础教程 第3章: 使用字符串 学习笔记
- JQuery学习笔记——基础知识和数组以及字符串操作
- python3.4学习笔记(十五) 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python学习笔记5-字符串、bool、数值操作和数组字典排序
- Python学习笔记七:字符串的操作(一)
- <<Python基础教程>>学习笔记 | 第03章 | 字符串
- Python学习笔记(23)-Python字符串常用操作
- python学习笔记.字典基础操作
- 【零基础入门学习Python笔记015】字符串:格式化
- Python基础教程学习笔记----第三章 字符串
- Python学习笔记5-字符串、bool、数值操作和数组字典排序
- Python学习笔记:02 基础:变量、整数、字符串、赋值、基本输出、注释、代码块
- python学习笔记之二:字符串操作
- python学习笔记之基础操作
- Python学习笔记--字符串操作string
- Python学习笔记七:字符串的操作(一)
- python学习笔记1(字符串操作)
- 【零基础入门学习Python笔记014】字符串:各种奇葩的内置方法
- Swift学习笔记(十六)——String字符串的基础操作