格式化字符串
print("%s %s" % ("foo", "bar"))
求长度
len("foo")
常用转码操作
How to encode URLs in Python
How do I treat an ASCII string as unicode and unescape the escaped characters in it in python?
urllib.parse.quote(query) # 该函数不转码斜线
urllib.parse.quote_plus(query) # 转码空格到加号的所有字符
# Unicode decode
str.encode("utf-8").decode("unicode_escape")
两边去空白字符
Python Trim String – rstrip(), lstrip(), strip()
"".strip() "".lstrip() "".rstrip()
截取
str = "foo-bar" str[0:4]
二进制 ⇔ 普通字符串
b'bin string'.decode('ascii')
参考文献
- WikiNotes/字符串操作(学习笔记)
- Python Strings
- How to convert 'binary string' to normal string in Python3?
最后
以上就是顺心黄蜂最近收集整理的关于# 2021-01-12 #「Python」- 字符串操作(学习笔记)的全部内容,更多相关#内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复