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

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

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

問題描述

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

Apparently, the following is the valid syntax:

my_string = b'The string'

我想知道:

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

我在 SO 上找到了一個(gè)相關(guān)問題,但這個(gè)問題是關(guān)于 PHP 的,它說明了 b 用于指示字符串是二進(jìn)制的,與 Unicode 不同,Unicode 是與 PHP 版本兼容所必需的.6,遷移到 PHP 6 時(shí).我認(rèn)為這不適用于 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.

我確實(shí)在 Python 網(wǎng)站上找到了關(guān)于使用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;它表明文字應(yīng)該成為字節(jié)文字在 Python 3 中(例如,當(dāng)代碼用 2to3 自動轉(zhuǎn)換).一個(gè)'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 文檔 指出:

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

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.

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

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 欧美精品中文字幕久久二区 | 中文字幕亚洲精品 | 中文字幕乱码一区二区三区 | 亚洲一区不卡在线 | 国产精品成人一区二区 | 亚洲国产一区二区三区四区 | 日韩精品一区二区三区中文字幕 | 久久69精品久久久久久久电影好 | 久久久激情 | 国产美女精品视频免费观看 | 午夜精品一区二区三区在线视频 | 一色桃子av一区二区 | 91精品久久久久久久久 | 午夜免费小视频 | 日韩图区| 欧美 日韩 国产 成人 | 久久精品视频播放 | 男女爱爱网站 | 亚洲激情在线视频 | 成人a在线观看 | 午夜精品久久久久久久久久久久久 | caoporn国产精品免费公开 | 欧美精品欧美精品系列 | 精品久久久久久久久久久 | 国内精品视频免费观看 | 九九热这里只有精品在线观看 | 日韩有码一区 | 国产探花在线精品一区二区 | 国产精品久久久久久网站 | 欧美日韩高清在线观看 | 日韩精品欧美精品 | 久久激情视频 | 在线色网 | 欧美成人精品 | 成人免费淫片aa视频免费 | 久久精品亚洲精品国产欧美kt∨ | 国产精品自产拍 | 欧美99 | 国产精品1区2区 | 国产四虎 | 99热热99|