diff --git a/Software/Development/Language/Python/Python_string_与_bytes_之间的转换.md b/Software/Development/Language/Python/Python_string_与_bytes.md similarity index 62% rename from Software/Development/Language/Python/Python_string_与_bytes_之间的转换.md rename to Software/Development/Language/Python/Python_string_与_bytes.md index 0ffa9c2..c5f322a 100644 --- a/Software/Development/Language/Python/Python_string_与_bytes_之间的转换.md +++ b/Software/Development/Language/Python/Python_string_与_bytes.md @@ -1,4 +1,4 @@ -# Python string 与 bytes 之间的转换 +# Python string 与 bytes 总的来说,bytes 和 string 的关系是: @@ -40,3 +40,23 @@ s = str(s, encoding = "utf8") # string s = '\\u4eca\\u5929\\u5929\\u6c14\\u4e0d\\u9519' # 中文是:今天天气真不错 new_s = s.encode().decode('unicode_escape') # 输出为:今天天气真不错 ``` + +## 4.string 开头 r/b/u/f 的含义 + +```python +b'input\n' # bytes字节符,打印以b开头。输出:b'input\n' +r'input\n' # 非转义原生字符,经处理'\n'变成了'\\'和'n'。也就是\n表示的是两个字符,而不是换行。输出:'input\\n' +u'input\n' # unicode编码字符,python3默认字符串编码方式。输出:'input\n' +``` + +f 开头: + +```python +import time +t0 = time.time() +time.sleep(1) +name = 'processing' +print(f'{name} done in {time.time() - t0:.2f} s') # 以f开头表示在字符串内支持大括号内的python 表达式 +输出: +processing done in 1.00 s +```