To quote the Python 2.x documentation:
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.
The Python 3 documentation states:
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.
Related Posts:
- What does the ‘b’ character do in front of a string literal?
- How to convert string to binary?
- Convert hex to binary
- How to convert string to binary?
- How to convert ‘binary string’ to normal string in Python3?
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- How do I lowercase a string in Python?
- How do I get a substring of a string in Python?
- How to read a file line-by-line into a list?
- strip(char) on a string
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Pythonic way to create a long multi-line string
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- TypeError: not all arguments converted during string formatting python
- How to resolve TypeError: can only concatenate str (not “int”) to str [duplicate]
- How do I append one string to another in Python?
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- How can I split and parse a string in Python?
- How to read a text file into a string variable and strip newlines?
- How to print like printf in Python3?
- Python convert tuple to string
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Split a string into 2 in Python
- Best way to strip punctuation from a string
- Split string with multiple delimiters in Python [duplicate]
- How to remove \xa0 from string in Python?
- How to check if the string is empty?
- How to find all occurrences of a substring?
- How to check whether a str(variable) is empty or not?
- Binary numbers in Python
- How to add a string in a certain position?
- Check string “None” or “not” in Python 2.7
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- Reading a binary file with python
- Convert columns to string in Pandas
- How to delete a character from a string using Python
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Convert decimal to binary in python
- How to check if a string is a substring of items in a list of strings?
- Best way to replace multiple characters in a string?
- How do I remove a substring from the end of a string?
- How can I splice a string?
- Detect whether a Python string is a number or a letter
- Finding all possible permutations of a given string in python
- How do I append one string to another in Python?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- Converting from a string to boolean in Python?
- Count the number of occurrences of a character in a string
- “Unicode Error “unicodeescape” codec can’t decode bytes… Cannot open text files in Python 3
- Python – ‘ascii’ codec can’t decode byte
- How do I check if there are duplicates in a flat list?
- How can I print variable and string on same line in Python?
- Remove quotes from String in Python
- Convert hex string to int in Python
- How can I check if character in a string is a letter? (Python)
- How can I find the first occurrence of a sub-string in a python string?
- How to concatenate items in a list to a single string?
- Replacing a character from a certain index
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- Properly formatted multiplication table
- How to get a function name as a string?
- Pandas error “Can only use .str accessor with string values”
- How to compare individual characters in two strings in Python 3
- Python string prints as [u’String’]
- NameError: global name ‘unicode’ is not defined – in Python 3
- Create nice column output in python
- TypeError: decoding str is not supported
- AttributeError: ‘str’ object has no attribute ‘items’
- How to pad zeroes to a string?
- Using unicode character u201c
- How does str(list) work?
- What is the difference between a string and a byte string?
- How do I convert a string to a double in Python?
- How can I copy a Python string?
- How to strip a specific word from a string?
- Converting integer to binary in python
- Checking if a string can be converted to float in Python
- Python conversion from binary string to hexadecimal
- How to get ° character in a string in python?
- TypeError: coercing to Unicode: need string or buffer, int found
- Python cant convert ‘list’ object to str error [closed]
- Using strip() to clean up a string
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- Python code to remove HTML tags from a string
- Cannot concatenate ‘str’ and ‘float’ objects?
- How to repeat individual characters in strings in Python
- How to write unicode strings into a file?
- When to use %r instead of %s in Python? [duplicate]
- Python – difference between two strings