久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

字符串文字前面的“b"字符有什么作用?

What does the #39;b#39; character do in front of a string literal?(字符串文字前面的“b字符有什么作用?)
本文介紹了字符串文字前面的“b"字符有什么作用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

顯然,以下是有效的語法:

Apparently, the following is the valid syntax:

my_string = b'The string'

我想知道:

  1. 字符串前面的這個b字符是什么意思?
  2. 使用有什么效果?
  3. 在什么情況下使用合適?

我在 SO 上找到了一個相關問題,但這個問題是關于 PHP 的,它說明了 b 用于指示字符串是二進制的,與 Unicode 不同,Unicode 是與 PHP 版本兼容所必需的.6,遷移到 PHP 6 時.我認為這不適用于 Python.

I found a related question right here on SO, but that question is about PHP though, and it states the b is used to indicate the string is binary, as opposed to Unicode, which was needed for code to be compatible from version of PHP < 6, when migrating to PHP 6. I don't think this applies to Python.

我確實在 Python 網站上找到了關于使用u 字符以相同的語法將字符串指定為 Unicode.不幸的是,它沒有在該文檔的任何地方提及 b 字符.

I did find this documentation on the Python site about using a u character in the same syntax to specify a string as Unicode. Unfortunately, it doesn't mention the b character anywhere in that document.

另外,出于好奇,有沒有比 bu 更多的符號來做其他事情?

Also, just out of curiosity, are there more symbols than the b and u that do other things?

推薦答案

引用 Python 2.x 文檔:

'b' 或 'B' 的前綴在蟒蛇2;它表明文字應該成為字節文字在 Python 3 中(例如,當代碼用 2to3 自動轉換).一個'u' 或 'b' 前綴可以后跟'r' 前綴.

A prefix of 'b' or 'B' is ignored in Python 2; it indicates that the literal should become a bytes literal in Python 3 (e.g. when code is automatically converted with 2to3). A 'u' or 'b' prefix may be followed by an 'r' prefix.

Python 3 文檔 指出:

字節文字總是以'b'或'B'為前綴;它們生成 bytes 類型而不是 str 類型的實例.它們可能只包含 ASCII 字符;數值為 128 或更大的字節必須用轉義符表示.

Bytes literals are always prefixed with 'b' or 'B'; they produce an instance of the bytes type instead of the str type. They may only contain ASCII characters; bytes with a numeric value of 128 or greater must be expressed with escapes.

這篇關于字符串文字前面的“b"字符有什么作用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲成av人片在线观看无码 | 欧美日韩一区二区三区在线观看 | 成人免费一级视频 | 在线观看中文视频 | 国产精品视频偷伦精品视频 | 中文字幕精品一区二区三区在线 | 久久久久国产 | 精久久久 | 91在线视频国产 | 色综合天天天天做夜夜夜夜做 | 黄频视频 | 91免费小视频 | 婷婷色在线播放 | 美女久久 | 国产精品99久久久久久久久 | 夜夜久久 | 欧美一级在线观看 | 国产精品久久久久久久久久久久 | 精品国产乱码久久久久久蜜臀 | 国产香蕉视频在线播放 | 国产精品明星裸体写真集 | 亚洲欧美日韩电影 | av一级久久| 亚洲一区二区久久 | 欧美性受 | 亚洲免费精品 | 久久亚洲一区二区三区四区 | 国产亚洲成av人片在线观看桃 | 国产91丝袜在线18 | 色必久久 | 欧美一级久久久猛烈a大片 日韩av免费在线观看 | 黄色精品| 日本精品一区二区三区在线观看视频 | 欧美 中文字幕 | 免费一区在线观看 | 狠狠插天天干 | 欧美色综合一区二区三区 | 天天精品在线 | 国产美女久久 | 国产一区二区久久 | 欧一区二区 |