Sideway
output.to from Sideway
Draft for Information Only

Content

Python Bytes Literal
 Definition of Python Bytes Literal
 Features of Python Bytes
  Python Bytes Notation
  Python Bytes Catalogue
  Python Bytes Prefix
  Python Bytes Characters
  Escape Sequences Characters
 Python Bytearray Literal
 Source and Reference

Python Bytes Literal

In general, a bytes literal is also one type of string literal. Howeve, logically, a string literal is a sequences of characters with each character representing one single unit of a string literal, or a string literal of length 1. While a bytes literal is a sequences of integers with each integer representing one single byte having ASCII value between 0 and 255 of a bytes literal. However, bytes with a numeric value of 128 or greater must be expressed with escapes. In other words, a bytes literal may be considered as a list of integer which can be retrieved by index [] as an integer or by list() as the whole list of integers. Or a bytes literal may be considered as a list of bytes literal which can then be retrieved by range of indexes [i:i+1] as one single unit of a bytes literal, or a bytes literal of length 1. Or by range of indexes [a:b] as a bytes literal of length (b-a). Or by range of indexes [:] as a bytes literal of whole length. image

Definition of Python Bytes Literal

A bytes literal is a sequence of ASCII characters.
bytesliteral::=bytesprefix(shortbytes | longbytes)
        bytesprefix::="b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"
        shortbytes::="'" shortbytesitem* "'" | '"' shortbytesitem* '"'
        longbytes::="'''" longbytesitem* "'''" | '"""' longbytesitem* '"""'
        shortbytesitem::=shortbyteschar | bytesescapeseq
        longbytesitem::=longbyteschar | bytesescapeseq
        shortbyteschar::=<any ASCII character except "\" or newline or the quote>
        longbyteschar::=<any ASCII character except "\">
        bytesescapeseq::="\" <any ASCII character>

Features of Python Bytes

The Python bytes of bytes literal in Python have some typical features.

Python Bytes Notation

Python bytes literal is also denoted by quotes. Since bytes literal shares the same denoting method with string literal, a bytes literal is always prefixed with a prefix b or B to create a bytes literal instance instead of the string literal instance. The ways to denote a Python bytes are. Single Quotes, b'...' or B'...'e.g. b'A single quoted byte' Double Quotes, b"..." or B"..."e.g. b'A double quoted byte' Triple Quotes, b'''...''', b"""...""", B'''...''' or B"""..."""e.g. b'''A triple quoted byte''', b"""A triple quoted byte""" image

Python Bytes Catalogue

Python bytes can be divided into shortbyte and longbyte. The difference betweens shortbyte and longbyte are: shortbyteEnclosed by single or double quotes. Does not allow reserved character backslash \, unescaped NEWLINE, and the corresponding quote ' or " image longbyteEnclosed by triple quotes. Does not allow reserved character backslash \ only image

Python Bytes Prefix

Python bytes Prefix is used to specify the rules to interpret the following bytes literal. Whitespace is not allowed between the bytes prefix and the rest of the bytes literal. The meanings of supported bytes prefixs are: b, BA bytes literal is always prefixed with a prefix b or B to create a bytes literal instance instead of the string literal instance. image br, Br, bR, BR, rb, rB, Rb, RBRaw formatted bytes literals are possible. image The fb syntax is not supported.

Python Bytes Characters

The Python bytes character set is any ASCII character. A bytes literal itself is a sequences of integers with each integer representing one single bytes having ASCII value between 0 and 255 of a bytes literal. However, bytes with a numeric value of 128 or greater must be expressed with escapes. image

Escape Sequences Characters

The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. The recognized escape sequences are: \<NEWLINE>Physically literal line break, logically BACKSLASH and NEWLINE are ignored. \\Backslash (\) \'Single quote (') \"Double quote (") \aASCII Bell (BEL) \bASCII Backspace (BS) \fASCII Formfeed (FF) \nASCII Linefeed (LF) \rASCII Carriage Return (CR) \tASCII Horizontal Tab (TAB) \vASCII Vertical Tab (VT) \oooCharacter with octal value ooo \xhhCharacter with hex value hh Note: Escape sequences only recognized in string literals are: \N{name}Character named name in the Unicode database \uxxxxCharacter with 16-bit hex value xxxx \UxxxxxxxxCharacter with 32-bit hex value xxxxxxxx image

Python Bytearray Literal

Since bytes literal is an immutable array of bytes (PyString), bytearray literal is designed as a mutable counterpart to bytes literal. In other words, bytearray literal is a mutable array of bytes (PyBytes). image

Source and Reference


©sideway

ID: 210100003 Last Updated: 1/3/2021 Revision: 0


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019