「Python」- 字符串操作(学习笔记) @20210212
作者:互联网
格式化字符串
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')
参考文献
Python Strings
How to convert 'binary string' to normal string in Python3?
标签:string,转码,Python,decode,How,字符串,20210212,foo 来源: https://www.cnblogs.com/k4nz/p/14399193.html