About 193,000 results
Open links in new tab
  1. How to write string literals in Python without having to escape …

    You will find Python's string literal documentation here: http://docs.python.org/tutorial/introduction.html#strings. and here: http://docs.python.org/reference/lexical_analysis.html#literals. The simplest example would be using the 'r' prefix: ss = r'Hello\nWorld' print(ss) Hello\nWorld

  2. python - What is the difference between string literals and string ...

    May 23, 2020 · In a string literal (except for raw string literals), special sequences of characters known as escape sequences in the string literal are replaced with different characters in the actual string. For example, the escape sequence \n in a string literal is replaced with a line feed character in the actual string.

  3. Python String Literals - W3Schools

    String Literals. String literals in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello". You can display a string literal with the print() function:

  4. Literals in Python - GeeksforGeeks

    Mar 5, 2025 · String Literals. String literals are sequences of characters enclosed in quotes. They are used to represent text in Python. Types of String Literals: Single-quoted strings – Enclosed in single quotes (‘ ‘). Example: ‘Hello, World!’ Double-quoted strings – Enclosed in double quotes (” “). Example: “Python is fun!”

  5. string — Common string operations — Python 3.13.3 …

    4 days ago · Loop over the format_string and return an iterable of tuples (literal_text, field_name, format_spec, conversion). This is used by vformat() to break the string into either literal text, or replacement fields.

  6. python - What exactly do "u" and "r" string prefixes do, and what …

    There are two types of string in Python 2: the traditional str type and the newer unicode type. If you type a string literal without the u in front you get the old str type which stores 8-bit characters, and with the u in front you get the newer unicode type that can store any Unicode character.

  7. Literals — typing documentation - Read the Docs

    Literal may be parameterized with literal ints, byte and unicode strings, bools, Enum values and None. So for example, all of the following would be legal: Note: Since the type None is inhabited by just a single value, the types None and Literal[None] are exactly equivalent. Type checkers may simplify Literal[None] into just None.

  8. PEP 586 – Literal Types | peps.python.org

    Feb 1, 2025 · We propose adding Literal types to address these gaps. This section outlines the baseline behavior of literal types. Literal types indicate that a variable has a specific and concrete value. For example, if we define some variable foo to have type Literal[3], we are declaring that foo must be exactly equal to 3 and no other value.

  9. String Literals in Python: A Comprehensive Guide - CodeRivers

    Mar 22, 2025 · In this blog post, we will explore the fundamental concepts of string literals in Python, their usage methods, common practices, and best practices. In Python, a string literal is a sequence of characters enclosed in quotes.

  10. Python String Literals: A Comprehensive Guide - CodeRivers

    Jan 23, 2025 · String literals are a way to represent strings in your Python code. They are sequences of characters enclosed in quotes. Whether you are writing a simple greeting message, parsing text data, or working on a complex natural language processing project, understanding string literals is crucial.

  11. Some results have been removed