- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print double quotes with the string variable in Python?
Printing double quotes is tricky, as it itself is required as part of syntax to print the strings by surrounding them. In this article we will see how these double quotes can be printed using print statement.
The below scenarios will not print the double quote. The first two lines of code will give no output while the last one will through error.
Example
print(" ") print(" " " ") print(""aString"")
Output
Running the above code gives us the following result −;
print(""aString"") ^ SyntaxError: invalid syntax
But if we surround the strings with proper quotes as shown below, then the quotes can themselves get printed. Enclosing double quotes within single quotes does the trick.
Example
print('Hello Tutorialspoint') print('"Hello Tutorialspoint"')
Output
Running the above code gives us the following result −
Hello Tutorialspoint "Hello Tutorialspoint"
Using string variables
We can also use string formatting to print the double quotes as well as any other character which is part of the print syntax.
Example
StringVar = 'Hello Tutorialspoint' print("\"%s\""% StringVar ) print("\%s\"% StringVar ) print('"%s"' % StringVar ) print('"{}"'.format(StringVar))
Output
Running the above code gives us the following result −
"Hello Tutorialspoint" \Hello Tutorialspoint\ "Hello Tutorialspoint" "Hello Tutorialspoint"
- Related Articles
- How to insert records with double quotes in MySQL?
- Single quotes vs. double quotes in C or C++
- Find records with double quotes in a MySQL column?
- What is the difference between single and double quotes in python?
- Single and Double Quotes in Perl
- How to use quotes correctly while using LIKE with search variable in MySQL in Java?
- How to print concatenated string in Python?
- How to Convert Double to String to Double in Java?
- Is there a PHP function that only adds slashes to double quotes NOT single quotes
- How to print a string two times with single statement in Python?
- Print newline in PHP in single quotes
- What is the difference between single and double quotes in JavaScript?
- Print Single and Multiple variable in Python?
- How to convert the Integer variable to the string variable in PowerShell?
- How to print a variable name in C?
