{"id":11778,"date":"2024-10-22T06:12:50","date_gmt":"2024-10-22T06:12:50","guid":{"rendered":"http:\/\/www.wscubetech.com\/blog\/?p=11778"},"modified":"2026-01-16T12:53:38","modified_gmt":"2026-01-16T12:53:38","slug":"print-newline-python","status":"publish","type":"post","link":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/","title":{"rendered":"How to Print a Newline in Python? With Examples"},"content":{"rendered":"\n<p>When we work with strings or text data, it often involves printing a new line. Generally, we use the print statement to print a string and another print statement to print it in a new line. After execution, when we write the print statement, the cursor automatically shifts to a new line. However, if we keep on writing new print statements repeatedly for every string, the code will become unclear and absurd.&nbsp;<\/p>\n\n\n\n<p>Hence, we use the escape character \u2018\\n\u2019 to print a newline in Python. In this blog, we will discuss the different ways to print a new line, along with some examples.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Print a Newline Using the \\n Escape Sequence<\/h2>\n\n\n\n<p>In Python, an escape sequence is a special character, providing a simple and common way to print a newline by using a backslash (\\). It represents a certain character or behavior. Using escape sequences, we can include characters in a string that are difficult to type directly into the code.&nbsp;<\/p>\n\n\n\n<p>We use escape sequences to add Python newline<strong> <\/strong>characters (\\n) to a string. A newline character represents the end of a text line and causes the next character to be printed on a new line.&nbsp;<\/p>\n\n\n\n<p>So, when a string has a newline character, Python will start a new line in the output. It is used to format text in a program or create multi-line strings.&nbsp;<\/p>\n\n\n\n<p>Let\u2019s understand this method through its functions, syntax, and more.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Character<\/h3>\n\n\n\n<p>&#8216;\\n&#8217;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Purpose<\/h3>\n\n\n\n<p>To shift the cursor to a new line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Features<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is an escape sequence character.<\/li>\n\n\n\n<li>It is valid for strings and characters only.<\/li>\n\n\n\n<li>It is also known as line-break.<\/li>\n\n\n\n<li>We can add \u2018\\n\u2019 anywhere in a string.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. Declare a string in multiple lines<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Str_var = \"\\nstring 1\\n string 2\\n\"&nbsp;&nbsp;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. Print a string in multiple lines<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>print (\"\\nstr1\\nstr2\\n\")&nbsp;&nbsp;<\/code><\/pre>\n\n\n\n<p><strong>Initial \\n- <\/strong>It leaves a blank line and shifts to a new line, printing str1.<\/p>\n\n\n\n<p><strong>Middle \\n- <\/strong>It prints str1 and then shifts to a new line<strong>, <\/strong>printing str2.<\/p>\n\n\n\n<p><strong>Final \\n- <\/strong>After executing str2, it leaves a blank line and shifts to a new line.<\/p>\n\n\n\n<p><strong>Also read:<\/strong> <a href=\"https:\/\/www.wscubetech.com\/blog\/python-developer-roadmap\/\">Python Developer Roadmap (Guide for Beginners)<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why do we need &#8216;\\n&#8217;?<\/h3>\n\n\n\n<p>If you want to print \u201cHello\u201d, \u201cMy\u201d, and \u201cFriends\u201d in three different lines, you will do it using the normal print statement as shown below:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Code&nbsp;<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>print (\"Hello\")  \nprint (\u201cMy\u201d)  \nprint (\"Friends\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello\nMy\nFriends<\/code><\/pre>\n\n\n\n<p>So, you would require 3 lines of code to print these words. It is a longer process and may not be useful for printing more strings. Therefore, we use \u2018\\n\u2019 as shown in the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print (\"Hello\\nMy\\nFriends\")  <\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello\nMy\nFriends <\/code><\/pre>\n\n\n\n<p>Here, you need to write one line of code to print a new line in Python. You can use \u2018\\n\u2019 to print any number of strings in multiple lines while keeping the code precise and simple.\u00a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">More About &#8216;\\n&#8217;<\/h3>\n\n\n\n<p>Many wonder how Python recognizes \u2018\\n\u2019 and why the print statement doesn\u2019t print \u2018\\n\u2019 like a normal string. Well, Python has a few predefined characters succeeding a backslash (\\), known as the escape sequences. Python easily recognizes \u2018\\\u2019, understands it\u2019s not part of a string, and executes it according to the succeeding character.&nbsp;<\/p>\n\n\n\n<p>When we use a backslash before a character, the character can escape the normal string execution. A few examples of these characters are \\t, \\r, \\n, etc.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example<\/strong><strong>&#8211; Declaring a string with &#8216;\\n&#8217;<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>message = \"Hello\\nPython\\nWorld\"\nprint(message)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello\nPython\nWorld<\/code><\/pre>\n\n\n\n    <!-- LOTTIE SCRIPT -->\n    <script src=\"https:\/\/unpkg.com\/@lottiefiles\/lottie-player@latest\/dist\/lottie-player.js\"><\/script>\n\n    <section class=\"wscube-courses\">\n        <div class=\"container\">\n            <h3 class=\"mb-4\">Recommended Professional <\/br> Certificates<\/h3>\n\n            <div class=\"owl-carousel courseOwl\">\n\n                \n                    \n                    <div class=\"course-card card-r rounded-4\">\n\n                        <!-- \u2705 SINGLE MEDIA DIV (FIXED) -->\n                        <div class=\"course-media\"\n                             data-lottie=\"https:\/\/www.wscubetech.com\/uploads\/images\/courses\/json-images\/web-devlopment.json\"\n                             data-fallback=\"https:\/\/www.wscubetech.com\/blog\/wp-content\/themes\/newwscube\/assets\/imges\/Image.png\">\n                        <\/div>\n\n                        <div class=\"card-body\">\n                            <h5>Full Stack Development Mentorship Program<\/h5>\n\n                            <p class=\"rating\">\n                                4.9 \u2605\u2605\u2605\u2605\u2605\n                                (24922)\n                            <\/p>\n\n                            <ul class=\"course-meta\">\n                                <li>\ud83d\udc64 27000 Learners<\/li>\n                                <li>\u23f1 17 Weeks<\/li>\n                            <\/ul>\n\n                            <div class=\"mt-3\">\n                                                                    <a href=\"https:\/\/www.wscubetech.com\/full-stack-developer-course?utm_source=WsBlog&#038;utm_medium=blog_course_slider&#038;utm_campaign=SEO\"\n                                       target=\"_blank\"\n                                       class=\"btn view-btn btn-sm\">\n                                        View Brochure\n                                    <\/a>\n                                \n                                <a target=\"_blank\"\n                                   href=\"https:\/\/www.wscubetech.com\/full-stack-developer-course?utm_source=WsBlog&#038;utm_medium=blog_course_slider&#038;utm_campaign=SEO\"\n                                   class=\"btn btn-outline-secondary btn-sm\">\n                                    Learn More\n                                <\/a>\n                            <\/div>\n                        <\/div>\n                    <\/div>\n\n                \n                    \n                    <div class=\"course-card card-r rounded-4\">\n\n                        <!-- \u2705 SINGLE MEDIA DIV (FIXED) -->\n                        <div class=\"course-media\"\n                             data-lottie=\"https:\/\/www.wscubetech.com\/uploads\/images\/courses\/json-images\/wordpress-v2.json\"\n                             data-fallback=\"https:\/\/www.wscubetech.com\/blog\/wp-content\/themes\/newwscube\/assets\/imges\/Image.png\">\n                        <\/div>\n\n                        <div class=\"card-body\">\n                            <h5>WordPress Bootcamp<\/h5>\n\n                            <p class=\"rating\">\n                                4.9 \u2605\u2605\u2605\u2605\u2605\n                                (9406)\n                            <\/p>\n\n                            <ul class=\"course-meta\">\n                                <li>\ud83d\udc64 16000 Learners<\/li>\n                                <li>\u23f1 2 Months<\/li>\n                            <\/ul>\n\n                            <div class=\"mt-3\">\n                                                                    <a href=\"https:\/\/www.wscubetech.com\/wordpress-course?utm_source=WsBlog&#038;utm_medium=blog_course_slider&#038;utm_campaign=SEO\"\n                                       target=\"_blank\"\n                                       class=\"btn view-btn btn-sm\">\n                                        View Brochure\n                                    <\/a>\n                                \n                                <a target=\"_blank\"\n                                   href=\"https:\/\/www.wscubetech.com\/wordpress-course?utm_source=WsBlog&#038;utm_medium=blog_course_slider&#038;utm_campaign=SEO\"\n                                   class=\"btn btn-outline-secondary btn-sm\">\n                                    Learn More\n                                <\/a>\n                            <\/div>\n                        <\/div>\n                    <\/div>\n\n                \n            <\/div>\n        <\/div>\n    <\/section>\n\n    \n\n\n\n<h2 class=\"wp-block-heading\">Print a Newline Using the print() Function&nbsp;<\/h2>\n\n\n\n<p>We can also use the print() function with the end parameter to print a newline character in Python. End is an optional parameter that mentions the last character with which to end the string.&nbsp;<\/p>\n\n\n\n<p>By default, this method adds a newline character at the end of the output, but to change this behavior, we specify a different string used as the end parameter.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>print(\"Hello\", end=\" \")\nprint(\"Python\", end=\" \")\nprint(\"World\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello Python World<\/code><\/pre>\n\n\n\n<p>The print() function used with the end parameter enhances code readability, making it clearer where to add the newline character. However, it can make the code complicated and verbose, especially when it contains lengthy text blocks.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Print a Newline Using the join() Method with the split() Method<\/h2>\n\n\n\n<p>Another way is to use the join() method with the split() method. It is an advanced way to print a newline character in Python. split() divides a string into substrings that are based on the specified separator. join() is used to join elements of a list into a single string. When we split a string on the newline character and join it back with a newline character separator, it allows us to print multiple lines of text.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Original string with spaces as separators\ntext = \"Hello Python World\"\n# Split the string into a list of words\nwords = text.split(\" \")\n# Join the words using a newline character (\\n)\nresult = \"\\n\".join(words)\nprint(result)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello\nPython\nWorld<\/code><\/pre>\n\n\n\n<p>Combining join() and split() makes the code clearer and more concise, improving code readability. However, printing multiple lines of text while working with lengthy blocks of text may not prove to be an effective method.&nbsp;<\/p>\n\n\n\n        <div class=\"container position-relative\">\n            <div class=\"row pb-4\">\n                <h2 style=\"font-size:32px\">Upcoming Masterclass<\/h2>\n                <p>Attend our live classes led by experienced and desiccated instructors of Wscube Tech.<\/p>\n            <\/div>\n            <div class=\"owl-carousel myOwl\">\n                <div class=\"item\">\n                    <a href=\"https:\/\/www.wscubetech.com\/events\/how-to-get-a-10-20-lpa-job-as-a-business-analyst?utm_source=WsBlog&utm_medium=blog_master_class_slider&utm_campaign=SEO\" target=\"_blank\">\n                        <img decoding=\"async\" src=\"https:\/\/deen3evddmddt.cloudfront.net\/uploads\/master-class-media\/Job as a Business Analyst sdfsd.png\" alt=\"How to Get a \u20b910\u201320 LPA Job as a Business Analyst\" \/>\n                    <\/a>\n                <\/div>\n                <div class=\"item\">\n                    <a href=\"https:\/\/www.wscubetech.com\/events\/winning-meta-ads-in-the-ai-era?utm_source=WsBlog&utm_medium=blog_master_class_slider&utm_campaign=SEO\" target=\"_blank\">\n                        <img decoding=\"async\" src=\"https:\/\/deen3evddmddt.cloudfront.net\/uploads\/master-class-media\/Winning Meta two.webp\" alt=\"Winning Meta Ads in the AI Era\" \/>\n                    <\/a>\n                <\/div>\n                <div class=\"item\">\n                    <a href=\"https:\/\/www.wscubetech.com\/events\/mastering-cyber-defense-in-the-ai-era-hack-proof-career-in-2026?utm_source=WsBlog&utm_medium=blog_master_class_slider&utm_campaign=SEO\" target=\"_blank\">\n                        <img decoding=\"async\" src=\"https:\/\/deen3evddmddt.cloudfront.net\/uploads\/master-class-media\/cs12april-full.webp\" alt=\"Mastering Cyber Defense in the AI Era\" \/>\n                    <\/a>\n                <\/div>\n            <\/div>\n        <\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Print a String in a New Line&nbsp;<\/h2>\n\n\n\n<p>This is another method to shift a string to a new line. We first use multiple print statements. We can also use the \u2018\\n\u2019 character. To achieve this, we use multi-line strings. Single or double quotes are used to print a single-line string. To print multiple lines of strings, we use 3 single quotes (&#8221;&#8217; string&#8221;&#8217;) or 3 double quotes (&#8220;&#8221;&#8221;strings&#8221;&#8221;&#8221;).&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Syntax<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>'''''String 1 \nString 2 \n............... \nString n'''  \n  \nOR  \n  \n\"\"\"String 1 \nString 2 \n.............. \nString n\"\"\" <\/code><\/pre>\n\n\n\n<p>Python can recognize that a string is a multi-line string through single quotes or double quotes.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Using triple double quotes to declare a multi-line string\nmulti_line_string = \"\"\"This is line A\nThis is line B\nThis is line C\"\"\"\n\n# Printing the multi-line string\nprint(multi_line_string)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>This is line A\nThis is line B\nThis is line C<\/code><\/pre>\n\n\n\n<p><strong>Also read:<\/strong> <a href=\"https:\/\/www.wscubetech.com\/blog\/python-developer-skills\/\">Top 21 Python Developer Skills You Must Have<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Effect of the Newline Characters on Code<\/h2>\n\n\n\n<p>There are different studies investigating the effect of newline characters on code maintainability and readability. According to a study, it is easier to read and understand code with consistent and predictable newline characters, which is beneficial for beginners. Also, inconsistent use of indentation or whitespace or excessive use of newline characters can make the code harder to read and understand. Therefore, we must use the newline character consistently and predictably, following the guidelines and conventions of Python programming.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.wscubetech.com\/full-stack-developer-course?utm_source=WsBlog&amp;utm_medium=Content_Banner&amp;utm_campaign=SEO&amp;utm_page=\/print-newline-python\/\" target=\"_blank\" rel=\" noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1546\" height=\"452\" src=\"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2025\/04\/full-stack-development-course.webp\" alt=\"\" class=\"wp-image-13736\" srcset=\"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2025\/04\/full-stack-development-course.webp 1546w, https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2025\/04\/full-stack-development-course-300x88.webp 300w, https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2025\/04\/full-stack-development-course-1024x299.webp 1024w, https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2025\/04\/full-stack-development-course-768x225.webp 768w, https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2025\/04\/full-stack-development-course-1536x449.webp 1536w\" sizes=\"auto, (max-width: 1546px) 100vw, 1546px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs &#8211; Print a Newline in Python<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1729514339414\"><strong class=\"schema-faq-question\">1. <strong>How do you print \\n in Python?<\/strong><\/strong> <p class=\"schema-faq-answer\">In Python, \u2018\\n\u2019 denotes a newline character that is used to print a new line. The print() function automatically adds a new line character at the end of the output. To change this, we need to set the end keyword argument to an empty string.\u00a0<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1729514360096\"><strong class=\"schema-faq-question\">2. <strong>What is a newline character in Python?<\/strong><\/strong> <p class=\"schema-faq-answer\">A Python newline character is represented by the special escape character \u2018\\n\u2019, which indicates the end of a line of text and the beginning of a new one.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1729514368205\"><strong class=\"schema-faq-question\">3. <strong>How to remove a newline in Python?<\/strong><\/strong> <p class=\"schema-faq-answer\">We can use various ways to remove a newline in Python. Let\u2019s see the two commonly used methods:<br\/><br\/>&#8211; <strong>Using strip() method<\/strong><br\/><br\/>The strip() method is an in-built function in Python and is the easiest way to remove newline characters and trailing spaces from a string. As we use this function, we check for \u2018\\n\u2019 as a string in a string. This method returns a copy of the original string, removing all the leading and trailing whitespace.<br\/><br\/> &#8211; <strong>Using split() and join()<\/strong><br\/><br\/>We can remove newline characters from a string using the split() and join() methods. split() is used to split the original string into a substring list based on the given delimiter. The join() method concatenates substrings to create a string and effectively removes the newline characters.\u00a0<\/p> <\/div> <\/div>\n\n\n\n<p>&nbsp;<strong>Conclusion<\/strong><\/p>\n\n\n\n<p>Now that you have explored the Python new line character, it\u2019s time to use it in your code to make it easier to read and understand. It will be specifically useful for code with multiple lines or long strings. Moreover, it helps you avoid the pitfalls of writing multiple print statements for every string. To acquire <a href=\"https:\/\/www.wscubetech.com\/blog\/python-developer-skills\/\">Python skill<\/a><a href=\"https:\/\/www.wscubetech.com\/blog\/python-developer-skills\/\" target=\"_blank\" rel=\"noreferrer noopener\">s<\/a> and become a professional coder, take our <a href=\"https:\/\/www.wscubetech.com\/python-course?utm_source=WsBlog&amp;utm_medium=BlogInterlink&amp;utm_campaign=traffic\" target=\"_blank\" rel=\"noreferrer noopener\">Python online course<\/a> that aims to take your proficiency to the next level.\u00a0<\/p>\n\n\n\n<p class=\"has-white-color has-vivid-cyan-blue-background-color has-text-color has-background has-link-color wp-elements-a801ed3c44adae2468141da64432604a\"><strong>Explore Our Free Tech Tutorials<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/python\" target=\"_blank\" rel=\"noreferrer noopener\">Python Tutorial<\/a><\/td><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/java\" target=\"_blank\" rel=\"noreferrer noopener\">Java Tutorial<\/a><\/td><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/javascript\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript Tutorial<\/a><\/td><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/dsa\" target=\"_blank\" rel=\"noreferrer noopener\">DSA Tutorial<\/a><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/c-programming\" target=\"_blank\" rel=\"noreferrer noopener\">C Tutorial<\/a><\/td><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/cpp\" target=\"_blank\" rel=\"noreferrer noopener\">C++ Tutorial<\/a><\/td><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/html\" target=\"_blank\" rel=\"noreferrer noopener\">HTML Tutorial<\/a><\/td><td class=\"has-text-align-center\" data-align=\"center\"><a href=\"https:\/\/www.wscubetech.com\/resources\/sql\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Tutorial<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>When we work with strings or text data, it often involves printing a new line. Generally, we use the print statement to print a string and another print statement to print it in a new line. After execution, when we write the print statement, the cursor automatically shifts to a new line. However, if we [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":11852,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68],"tags":[],"class_list":["post-11778","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Print a Newline in Python? With Examples<\/title>\n<meta name=\"description\" content=\"Learn how to print a newline in Python with simple examples. Explore different methods to add line breaks in your code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wscubetech.com\/blog\/print-newline-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 a Newline in Python? With Examples\" \/>\n<meta property=\"og:description\" content=\"Learn how to print a newline in Python with simple examples. Explore different methods to add line breaks in your code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/\" \/>\n<meta property=\"og:site_name\" content=\"WsCube Tech Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wscubetech.india\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-22T06:12:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-16T12:53:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"780\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Ashima Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@wscube\" \/>\n<meta name=\"twitter:site\" content=\"@wscube\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashima Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/\",\"url\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/\",\"name\":\"How to Print a Newline in Python? With Examples\",\"isPartOf\":{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp\",\"datePublished\":\"2024-10-22T06:12:50+00:00\",\"dateModified\":\"2026-01-16T12:53:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/#\/schema\/person\/6995f82316ae760c1856b1bff807a793\"},\"description\":\"Learn how to print a newline in Python with simple examples. Explore different methods to add line breaks in your code.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514339414\"},{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514360096\"},{\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514368205\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#primaryimage\",\"url\":\"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp\",\"contentUrl\":\"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp\",\"width\":780,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.wscubetech.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Print a Newline in Python? With Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/#website\",\"url\":\"https:\/\/www.wscubetech.com\/blog\/\",\"name\":\"WsCube Tech Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wscubetech.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/#\/schema\/person\/6995f82316ae760c1856b1bff807a793\",\"name\":\"Ashima Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7660a6dae5a26ff506f0be04c3c35807480f565ca201c63311fd4bfa47ff02a0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7660a6dae5a26ff506f0be04c3c35807480f565ca201c63311fd4bfa47ff02a0?s=96&d=mm&r=g\",\"caption\":\"Ashima Jain\"},\"description\":\"Ashima Jain is a Content Editor and Strategist at WsCube Tech and has been in the content marketing industry for 6 years.\",\"url\":\"https:\/\/www.wscubetech.com\/blog\/author\/ashima\/\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514339414\",\"position\":1,\"url\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514339414\",\"name\":\"1. How do you print \\\\n in Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"In Python, \u2018\\\\n\u2019 denotes a newline character that is used to print a new line. The print() function automatically adds a new line character at the end of the output. To change this, we need to set the end keyword argument to an empty string.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514360096\",\"position\":2,\"url\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514360096\",\"name\":\"2. What is a newline character in Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"A Python newline character is represented by the special escape character \u2018\\\\n\u2019, which indicates the end of a line of text and the beginning of a new one.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514368205\",\"position\":3,\"url\":\"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514368205\",\"name\":\"3. How to remove a newline in Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"We can use various ways to remove a newline in Python. Let\u2019s see the two commonly used methods:<br\/><br\/>- <strong>Using strip() method<\/strong><br\/><br\/>The strip() method is an in-built function in Python and is the easiest way to remove newline characters and trailing spaces from a string. As we use this function, we check for \u2018\\\\n\u2019 as a string in a string. This method returns a copy of the original string, removing all the leading and trailing whitespace.<br\/><br\/> - <strong>Using split() and join()<\/strong><br\/><br\/>We can remove newline characters from a string using the split() and join() methods. split() is used to split the original string into a substring list based on the given delimiter. The join() method concatenates substrings to create a string and effectively removes the newline characters.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Print a Newline in Python? With Examples","description":"Learn how to print a newline in Python with simple examples. Explore different methods to add line breaks in your code.","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:\/\/www.wscubetech.com\/blog\/print-newline-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Print a Newline in Python? With Examples","og_description":"Learn how to print a newline in Python with simple examples. Explore different methods to add line breaks in your code.","og_url":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/","og_site_name":"WsCube Tech Blog","article_publisher":"https:\/\/www.facebook.com\/wscubetech.india","article_published_time":"2024-10-22T06:12:50+00:00","article_modified_time":"2026-01-16T12:53:38+00:00","og_image":[{"width":780,"height":400,"url":"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp","type":"image\/webp"}],"author":"Ashima Jain","twitter_card":"summary_large_image","twitter_creator":"@wscube","twitter_site":"@wscube","twitter_misc":{"Written by":"Ashima Jain","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/","url":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/","name":"How to Print a Newline in Python? With Examples","isPartOf":{"@id":"https:\/\/www.wscubetech.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#primaryimage"},"image":{"@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp","datePublished":"2024-10-22T06:12:50+00:00","dateModified":"2026-01-16T12:53:38+00:00","author":{"@id":"https:\/\/www.wscubetech.com\/blog\/#\/schema\/person\/6995f82316ae760c1856b1bff807a793"},"description":"Learn how to print a newline in Python with simple examples. Explore different methods to add line breaks in your code.","breadcrumb":{"@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514339414"},{"@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514360096"},{"@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514368205"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wscubetech.com\/blog\/print-newline-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#primaryimage","url":"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp","contentUrl":"https:\/\/www.wscubetech.com\/blog\/wp-content\/uploads\/2024\/10\/print-newline-in-python.webp","width":780,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.wscubetech.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Print a Newline in Python? With Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.wscubetech.com\/blog\/#website","url":"https:\/\/www.wscubetech.com\/blog\/","name":"WsCube Tech Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wscubetech.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wscubetech.com\/blog\/#\/schema\/person\/6995f82316ae760c1856b1bff807a793","name":"Ashima Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wscubetech.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7660a6dae5a26ff506f0be04c3c35807480f565ca201c63311fd4bfa47ff02a0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7660a6dae5a26ff506f0be04c3c35807480f565ca201c63311fd4bfa47ff02a0?s=96&d=mm&r=g","caption":"Ashima Jain"},"description":"Ashima Jain is a Content Editor and Strategist at WsCube Tech and has been in the content marketing industry for 6 years.","url":"https:\/\/www.wscubetech.com\/blog\/author\/ashima\/"},{"@type":"Question","@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514339414","position":1,"url":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514339414","name":"1. How do you print \\n in Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"In Python, \u2018\\n\u2019 denotes a newline character that is used to print a new line. The print() function automatically adds a new line character at the end of the output. To change this, we need to set the end keyword argument to an empty string.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514360096","position":2,"url":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514360096","name":"2. What is a newline character in Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"A Python newline character is represented by the special escape character \u2018\\n\u2019, which indicates the end of a line of text and the beginning of a new one.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514368205","position":3,"url":"https:\/\/www.wscubetech.com\/blog\/print-newline-python\/#faq-question-1729514368205","name":"3. How to remove a newline in Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"We can use various ways to remove a newline in Python. Let\u2019s see the two commonly used methods:<br\/><br\/>- <strong>Using strip() method<\/strong><br\/><br\/>The strip() method is an in-built function in Python and is the easiest way to remove newline characters and trailing spaces from a string. As we use this function, we check for \u2018\\n\u2019 as a string in a string. This method returns a copy of the original string, removing all the leading and trailing whitespace.<br\/><br\/> - <strong>Using split() and join()<\/strong><br\/><br\/>We can remove newline characters from a string using the split() and join() methods. split() is used to split the original string into a substring list based on the given delimiter. The join() method concatenates substrings to create a string and effectively removes the newline characters.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/posts\/11778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/comments?post=11778"}],"version-history":[{"count":14,"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/posts\/11778\/revisions"}],"predecessor-version":[{"id":17018,"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/posts\/11778\/revisions\/17018"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/media\/11852"}],"wp:attachment":[{"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/media?parent=11778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/categories?post=11778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wscubetech.com\/blog\/wp-json\/wp\/v2\/tags?post=11778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}