current position:Home>Python string preceded by 'f' R 'B' U '

Python string preceded by 'f' R 'B' U '

2022-05-15 05:35:42A small pit of goods

String preceded by f

With f The beginning indicates that within the string, the python expression

print(f'{
      name} done in {
      time.time() - t0:.2f} s') 
 Output :
processing done in 1.00 s

String preceded by r

effect : The string after the declaration is a normal string , Relative , The special string contains : Escape character \n \t What's that .

"""  In a string , There is a special character : Escape character \, Such as : \a  Ring the bell (BEL) \b  Backspace  \t  tabs  \r  enter (CR) , Move the current position to the beginning of the line  \n  Line break (LF) , Moves the current position to the beginning of the next line  \\  Represents a backslash  \ \'  Represents a single quotation mark  ' \"  Represents a double quotation mark  " \?  Represents a question mark  ?  In a string , Encounter the above character combination , Will automatically escape   stay Python Add... Before the string in r, Equivalent to in all \ Add one more \, become \\,\\ To be escaped as \, To avoid \ escape n,t,r Equal character ,\ No longer represents escape characters ( No escape )  summary :\ For escape characters , Have escape ability ,'\\' or r'\' Lose escape ability   Represents a common character \ """

String preceded by b

example : response = b'Hello World!'b' ' That means this is one bytes object

effect :b" " A prefix : The following string is bytes type .

use : Network programming , Servers and browsers only recognize bytes Type data .

Such as :send The parameters of the function and recv The return value of the function is bytes type

attach : stay Python3 in ,bytes and str The way of mutual conversion is

str.encode(‘utf-8')

bytes.decode(‘utf-8')


String preceded by u

example :u" I'm a string of Chinese characters ."

effect :

String followed by Unicode Format Encoding , Usually used in front of Chinese string , Prevent source storage format problems , It leads to garbled code when it is used again .


It will be updated from time to time , If there is a mistake , Welcome to correct

copyright notice
author[A small pit of goods],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/135/202205142240049805.html

Random recommended