Open links in new tab
  1. python - What does the 'b' character do in front of a string literal ...

    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).

    • Reviews: 6

      Code sample

      >>> b'\xEF\xBB\xBF' + 'Text with a UTF-8 BOM'
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: can&#39;t concat bytes to str
    • Unicode & Character Encodings in Python: A Painless Guide

      May 20, 2019 · In this tutorial, you'll get a Python-centric introduction to character encodings and unicode. Handling character encodings and numbering systems …

    • Python `u` Prefix: Unveiling the Mysteries of Unicode Strings

      Jan 24, 2025 · Understanding the `u` prefix is essential for working with multilingual text, internationalization, and avoiding encoding - related bugs. This blog post will delve deep into the …

    • Demystifying the "u" Prefix for Unicode Strings in Python

      Nov 11, 2023 · When placed before a string literal like u"Hello world", the "u" prefix in Python specifies that the string should be interpreted as Unicode. This provides a way to handle text with international …

    • Unicode and character encodings - Python Basics

      Dec 21, 2025 · Encoding Latin letters in UTF-8 and then decoding them in UTF-16 resulted in a text that also contains characters from the Chinese, Japanese or …

    • People also ask
      Loading
      Unable to load answer
    • PEP 263 – Defining Python Source Code Encodings

      Jun 6, 2001 · This PEP proposes to introduce a syntax to declare the encoding of a Python source file. The encoding information is then used by the Python parser to …

    • Unraveling the Mysterious "u" in Python - CodeRivers

      Feb 28, 2025 · In the realm of Python programming, the prefix "u" can sometimes seem like an enigma to beginners. This blog post aims to demystify the meaning of "u" in Python, exploring its fundamental …

    • Unicode and character encodings - Python Basics 24.3.0

      Encoding Latin letters in UTF-8 and then decoding them in UTF-16 resulted in a text that also contains characters from the Chinese, Japanese or Korean language …

    • Effect of 'b' character in front of a string literal in Python

      Jul 23, 2025 · Byte strings are shown with a b prefix and surrounded by single or double quotes. Strings are Unicode by default and are human-readable. Strings are converted to bytes, using encoding. There …