How to use quotes inside of a string - Python Last Updated : 09 Dec, 2024 Comments Improve Suggest changes Like Article Like Report In Python programming, almost every character has a special meaning. The same goes with double quotes (" ") and single quotes (' '). These are used to define a character or a string. But sometimes there may arise a need to print these quotes in the output. However, the Python interpreter may raise a syntax error. Fortunately, there are various ways to achieve this.Let us see a simple example of using quotes inside a String in Python. Python # single quotes inside double quotes s = "Hello, 'GeeksforGeeks'" print(s) # double quotes inside single quotes s = 'Hello, "GeeksforGeeks"' print(s) OutputHello, 'GeeksforGeeks' Hello, "GeeksforGeeks" Now let’s explore other different methods to use quotes inside a String.Table of ContentUsing Escape SequenceUsing Triple QuotesUsing Escape SequencePython escape sequence are used to add some special characters in to the String. One of these characters is quotes, single or double. This can be done using the backslash (\) before the quotation characters. Python # escape sequence with double quotes s = "Hello, \"GeeksforGeeks\"" print(s) # escape sequence with single quotes s = 'Hello, \'GeeksforGeeks\'' print(s) # escape sequence with both single and double quotes s = "Hello, \"GeeksforGeeks\" and \'hey Geeks'" print(s) OutputHello, "GeeksforGeeks" Hello, 'GeeksforGeeks' Hello, "GeeksforGeeks" and 'hey Geeks' Using Triple Quotes triple quotes (""" or ''') in Python work as a pre-formatted block. This also follows alternative quote usage, i.e., if double quotes are used to enclose the whole string, then direct speech should be in single quotes and vise-versa. Python # single quotes inside triple double quotes s = """Hello, 'GeeksforGeeks'""" print(s) # double quotes inside triple single quotes s = '''Hello, "GeeksforGeeks"''' print(s) s = '''Hello, "GeeksforGeeks" And Hey Geeks''' print(s) OutputHello, 'GeeksforGeeks' Hello, "GeeksforGeeks" Hello, "GeeksforGeeks" And Hey Geeks Comment More infoAdvertise with us Next Article How to use quotes inside of a string - Python T tanyasehr88x Follow Improve Article Tags : Python Python Programs python-string Practice Tags : python Similar Reads How to Remove a Substring in Python? In Python, removing a substring from a string can be achieved through various methods such as using replace() function, slicing, or regular expressions. Depending on your specific use case, you may want to remove all instances of a substring or just the first occurrence. Letâs explore different ways 2 min read How to Initialize a String in Python In Python, initializing a string variable is straightforward and can be done in several ways. Strings in Python are immutable sequences of characters enclosed in either single quotes, double quotes or triple quotes. Letâs explore how to efficiently initialize string variables.Using Single or Double 2 min read How to Append to String in Python ? In Python, Strings are immutable datatypes. So, appending to a string is nothing but string concatenation which means adding a string at the end of another string.Let us explore how we can append to a String with a simple example in Python.Pythons = "Geeks" + "ForGeeks" print(s)OutputGeeksForGeeks N 2 min read How to copy a string in Python Creating a copy of a string is useful when we need a duplicate of a string to work with while keeping the original string intact, strings in Python are immutable which means they can't be altered after creation, so creating a copy sometimes becomes a necessity for specific use cases.Using SlicingSli 2 min read Printing String with double quotes - Python Printing a string with double quotes means displaying a string enclosed in double quotes (") as part of the output. This can be helpful when we want to make it clear that the text itself is a string or when quotes are essential to the context.Using Escape Characters (\")Escape the double quotes insi 2 min read Like