{"id":26679,"date":"2022-04-02T20:20:57","date_gmt":"2022-04-02T14:50:57","guid":{"rendered":"https:\/\/python-programs.com\/?p=26679"},"modified":"2022-04-02T20:20:57","modified_gmt":"2022-04-02T14:50:57","slug":"how-to-print-quotation-marks-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/","title":{"rendered":"How to Print Quotation Marks in Python?"},"content":{"rendered":"

Python does not allow double quotes within double quotes and single quotes within single quotes, which results in an error. It only enables opposing quotes, such as a double quote within a single quote and a single quote within a double quote.<\/p>\n

Invalid quotes:<\/strong><\/p>\n

\" \"Python-programs\" \"\r\n\r\n' 'Python-programs' '<\/pre>\n

Python Quotation Marks<\/h2>\n

1)Double quotes(” “)in Python<\/h4>\n

Printing double quotes is difficult because it is necessary as part of the syntax to enclose the strings. In this post, we’ll look at how to print these double-quotes using the print statement.<\/p>\n

The double-quote will not be printed in the cases below. The first two lines of code will produce no output, while the last will produce an error.<\/p>\n

Example1<\/strong><\/p>\n

print(\" \")\r\nprint(\" \" \" \")<\/pre>\n

Output:<\/strong><\/p>\n

<\/pre>\n

Explanation:<\/strong><\/p>\n

It doesn't gove any output since double-quotes inside a double-quotes is Invalid<\/pre>\n

Example2<\/strong><\/p>\n

print(\"\"Python-programs\"\")<\/pre>\n

Output:<\/strong><\/p>\n

 File \"<ipython-input-12-ba874bef0698>\", line 1\r\nprint(\"\"Python-programs\"\")\r\n^\r\nSyntaxError: invalid syntax<\/pre>\n

So to print the double quotes use the below code<\/p>\n

Example3<\/strong><\/p>\n

# Give the doule-quoted string as static input and store it in a variable\r\ngvn_str = '\"Welcome to Python-programs\"'\r\n# Print the given string\r\nprint(gvn_str)<\/pre>\n

Output:<\/strong><\/p>\n

\"Welcome to Python-programs\"<\/pre>\n

2)Single quotes(‘ ‘) in Python<\/h4>\n

Example1<\/strong><\/p>\n

print(' ')\r\nprint('' '')<\/pre>\n

Output:<\/strong><\/p>\n

<\/pre>\n

Explanation:<\/strong><\/p>\n

It doesn't gove any output since single-quotes inside a single-quotes is Invalid<\/pre>\n

Example2<\/strong><\/p>\n

# Give the string as static input and store it in a variable\r\ngvn_str = \"'Welcome to Python-programs'\"\r\n# Print the given string\r\nprint(gvn_str)<\/pre>\n

Output:<\/strong><\/p>\n

'Welcome to Python-programs'<\/pre>\n

Example3<\/strong><\/p>\n

# Give the string as static input and store it in a variable\r\ngvn_str = \"good morning 'Python-programs' hello\"\r\n# Print the given string\r\nprint(gvn_str)<\/pre>\n

Output:<\/strong><\/p>\n

good morning 'Python-programs' hello<\/pre>\n

String variables in Python<\/h3>\n

String formatting can also be used to print the double quotes as well as any other character that is part of the print syntax.<\/p>\n

gvn_str = 'Welcome to Python-programs'\r\nprint(\"\\\"%s\\\"\"% gvn_str )\r\nprint('\"%s\"' % gvn_str )\r\nprint(\"\\\\%s\\\\\"% gvn_str )\r\nprint('\"{}\"'.format(gvn_str))<\/pre>\n

Output:<\/strong><\/p>\n

\"Welcome to Python-programs\"\r\n\"Welcome to Python-programs\"\r\n\\Welcome to Python-programs\\\r\n\"Welcome to Python-programs\"<\/pre>\n","protected":false},"excerpt":{"rendered":"

Python does not allow double quotes within double quotes and single quotes within single quotes, which results in an error. It only enables opposing quotes, such as a double quote within a single quote and a single quote within a double quote. Invalid quotes: ” “Python-programs” ” ‘ ‘Python-programs’ ‘ Python Quotation Marks 1)Double quotes(” …<\/p>\n

How to Print Quotation Marks in Python?<\/span> Read More »<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[],"yoast_head":"\nHow to Print Quotation Marks in Python? - Python Programs<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Print Quotation Marks in Python? - Python Programs\" \/>\n<meta property=\"og:description\" content=\"Python does not allow double quotes within double quotes and single quotes within single quotes, which results in an error. It only enables opposing quotes, such as a double quote within a single quote and a single quote within a double quote. Invalid quotes: " "Python-programs" " ' 'Python-programs' ' Python Quotation Marks 1)Double quotes(” … How to Print Quotation Marks in Python? Read More »\" \/>\n<meta property=\"og:url\" content=\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Programs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/btechgeeks\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-02T14:50:57+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@btech_geeks\" \/>\n<meta name=\"twitter:site\" content=\"@btech_geeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vikram Chiluka\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/python-programs.com\/#organization\",\"name\":\"BTech Geeks\",\"url\":\"https:\/\/python-programs.com\/\",\"sameAs\":[\"https:\/\/www.instagram.com\/btechgeeks\/\",\"https:\/\/www.linkedin.com\/in\/btechgeeks\",\"https:\/\/in.pinterest.com\/btechgeek\/\",\"https:\/\/www.youtube.com\/channel\/UC9MlCqdJ3lKqz2p5114SDIg\",\"https:\/\/www.facebook.com\/btechgeeks\",\"https:\/\/twitter.com\/btech_geeks\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png\",\"contentUrl\":\"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png\",\"width\":350,\"height\":70,\"caption\":\"BTech Geeks\"},\"image\":{\"@id\":\"https:\/\/python-programs.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/python-programs.com\/#website\",\"url\":\"https:\/\/python-programs.com\/\",\"name\":\"Python Programs\",\"description\":\"Python Programs with Examples, How To Guides on Python\",\"publisher\":{\"@id\":\"https:\/\/python-programs.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/python-programs.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#webpage\",\"url\":\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/\",\"name\":\"How to Print Quotation Marks in Python? - Python Programs\",\"isPartOf\":{\"@id\":\"https:\/\/python-programs.com\/#website\"},\"datePublished\":\"2022-04-02T14:50:57+00:00\",\"dateModified\":\"2022-04-02T14:50:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/python-programs.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Print Quotation Marks in Python?\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#webpage\"},\"author\":{\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/fb109fd98e2d5a15fd4dac9970797602\"},\"headline\":\"How to Print Quotation Marks in Python?\",\"datePublished\":\"2022-04-02T14:50:57+00:00\",\"dateModified\":\"2022-04-02T14:50:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#webpage\"},\"wordCount\":177,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/python-programs.com\/#organization\"},\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/fb109fd98e2d5a15fd4dac9970797602\",\"name\":\"Vikram Chiluka\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c56c77f578d45de43af6feb443618ed7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c56c77f578d45de43af6feb443618ed7?s=96&d=mm&r=g\",\"caption\":\"Vikram Chiluka\"},\"url\":\"https:\/\/python-programs.com\/author\/vikram\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Print Quotation Marks in Python? - Python Programs","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Print Quotation Marks in Python? - Python Programs","og_description":"Python does not allow double quotes within double quotes and single quotes within single quotes, which results in an error. It only enables opposing quotes, such as a double quote within a single quote and a single quote within a double quote. Invalid quotes: \" \"Python-programs\" \" ' 'Python-programs' ' Python Quotation Marks 1)Double quotes(” … How to Print Quotation Marks in Python? Read More »","og_url":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/","og_site_name":"Python Programs","article_publisher":"https:\/\/www.facebook.com\/btechgeeks","article_published_time":"2022-04-02T14:50:57+00:00","twitter_card":"summary_large_image","twitter_creator":"@btech_geeks","twitter_site":"@btech_geeks","twitter_misc":{"Written by":"Vikram Chiluka","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/python-programs.com\/#organization","name":"BTech Geeks","url":"https:\/\/python-programs.com\/","sameAs":["https:\/\/www.instagram.com\/btechgeeks\/","https:\/\/www.linkedin.com\/in\/btechgeeks","https:\/\/in.pinterest.com\/btechgeek\/","https:\/\/www.youtube.com\/channel\/UC9MlCqdJ3lKqz2p5114SDIg","https:\/\/www.facebook.com\/btechgeeks","https:\/\/twitter.com\/btech_geeks"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/python-programs.com\/#\/schema\/logo\/image\/","url":"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png","contentUrl":"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png","width":350,"height":70,"caption":"BTech Geeks"},"image":{"@id":"https:\/\/python-programs.com\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/python-programs.com\/#website","url":"https:\/\/python-programs.com\/","name":"Python Programs","description":"Python Programs with Examples, How To Guides on Python","publisher":{"@id":"https:\/\/python-programs.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/python-programs.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#webpage","url":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/","name":"How to Print Quotation Marks in Python? - Python Programs","isPartOf":{"@id":"https:\/\/python-programs.com\/#website"},"datePublished":"2022-04-02T14:50:57+00:00","dateModified":"2022-04-02T14:50:57+00:00","breadcrumb":{"@id":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/python-programs.com\/"},{"@type":"ListItem","position":2,"name":"How to Print Quotation Marks in Python?"}]},{"@type":"Article","@id":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#article","isPartOf":{"@id":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#webpage"},"author":{"@id":"https:\/\/python-programs.com\/#\/schema\/person\/fb109fd98e2d5a15fd4dac9970797602"},"headline":"How to Print Quotation Marks in Python?","datePublished":"2022-04-02T14:50:57+00:00","dateModified":"2022-04-02T14:50:57+00:00","mainEntityOfPage":{"@id":"https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#webpage"},"wordCount":177,"commentCount":0,"publisher":{"@id":"https:\/\/python-programs.com\/#organization"},"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/python-programs.com\/how-to-print-quotation-marks-in-python\/#respond"]}]},{"@type":"Person","@id":"https:\/\/python-programs.com\/#\/schema\/person\/fb109fd98e2d5a15fd4dac9970797602","name":"Vikram Chiluka","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/python-programs.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c56c77f578d45de43af6feb443618ed7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c56c77f578d45de43af6feb443618ed7?s=96&d=mm&r=g","caption":"Vikram Chiluka"},"url":"https:\/\/python-programs.com\/author\/vikram\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/26679"}],"collection":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/comments?post=26679"}],"version-history":[{"count":6,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/26679\/revisions"}],"predecessor-version":[{"id":26685,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/26679\/revisions\/26685"}],"wp:attachment":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/media?parent=26679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/categories?post=26679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/tags?post=26679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}