Sideway
output.to from Sideway
Draft for Information Only

Content

Python Textual Sequence Types
 Python Textual Strings
 Python Textual Literals
 Python Textual Constructor
  class 𝑠𝑡𝑟
  Parameter
  Remarks
 Source and Reference

Python Textual Sequence Types

Python textual data is implemented as Python string which may be handled by predefined 𝑠𝑡𝑟 iteration objects, called string in general. There are two types of textual sequences, namely text sequence, and binary sequence. However, in practice, a string is usually refered to a text sequence, while a bytes or bytearray is usually refered to a binary sequence. Therefore, methods of 𝑠𝑡𝑟 are used to manipulate Python text sequence, Python string only.

Python Textual Strings

The Python textual sequence of Python strings are stored as immutable sequences of Unicode code points internally. The type constructor of Python strings is designed to handled all kinds of Python textual data for both representation of printable string or byes like objects. Python does not have an individual character type for Python textual sequence of Python string, the indexing of a Python string produces strings of length 1. e.g. for a non-empty string s, s[0]==s[0:1]. Python also does not have a mutable Python string type, but various methods are provided to construct strings from a given Python string type. However Python do have a mutable Python bytearray type corresponding to the immutable Python bytes type. image

Python Textual Literals

Python textual strings may be coustrusted by textual literals, string and bytes literals, directly. Besides, a single expression of several textual literals separated by whitespace only will be implicitly converted to a single textual literal. String LiteralsSingle quotes: For allowing embedded double quotes. e.g. 'allows embedded "double" quotes' Double quotes: For allowing embedded single quotes. e.g. "allows embedded 'single' quotes" Triple quoted: For allowing embedded single and double quotes. Besides triple quoted strings may span multiple lines and all associated whitespace will be included in the string literal. e.g. '''Three single quotes''', """Three double quotes""" image Bytes LiteralsSingle quotes: For allowing embedded double quotes. e.g. b'allows embedded "double" quotes' Double quotes: For allowing embedded single quotes. e.g. b"allows embedded 'single' quotes" Triple quoted: For allowing embedded single and double quotes. Besides triple quoted strings may span multiple lines and all associated whitespace will be included in the bytes literal. e.g. b'''Three single quotes''', b"""Three double quotes""" image

Python Textual Constructor

class 𝑠𝑡𝑟

class 𝑠𝑡𝑟(object='')
class 𝑠𝑡𝑟(object=b'', encoding='utf-8', errors='strict')

Parameter

class 𝑠𝑡𝑟To return a string version of object. The behavior of 𝑠𝑡𝑟() depends on whether the arguments, encoding or errors is given or not. object=''To specify a textual string object. Default object is an empty string objects object=b''To specify a textual binary string object. Default object is an empty binary string object. encoding='utf-8'To specify the encoding of the textual binary string object. Defualt is utf-8. errors='strict'to specify the error handling method of the textual binary string object.

Remarks

  • For calling 𝑠𝑡𝑟() function with neither encoding nor errors argument is given, the 𝑠𝑡𝑟(object) function returns object.__str__(), the informal readable printing string representation of the object. If the given object is a string object, the return is the string itself. If object does not have a __str__() method, then 𝑠𝑡𝑟() returns repr(object), the formal Python informative string presentation of the object. image
  • For calling 𝑠𝑡𝑟() function with at least one encoding or errors argument is given, the object should be a bytes-like object, e.g. bytes or bytearray. Or may cause TypeError. The function itself, 𝑠𝑡𝑟(bytes, encoding, errors) is equivalent to bytes.decode(encoding,errors). image
  • However, when calling 𝑠𝑡𝑟() function with neither encoding nor errors argument is given for a bytes-like object, the 𝑠𝑡𝑟() function returns the informal string representation as in the first case. image

Source and Reference


©sideway

ID: 210100012 Last Updated: 1/12/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