Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print empty line?

I am following a beginners tutorial on Python, there is a small exercise where I have to add an extra function call and print a line between verses, this works fine if I print an empty line in between function calls but if I add an empty print line to the end of my happyBirthday() I get an indent error, without the added print line all works fine though, any suggestions as to why?

Here is the code:

def happyBirthday(person):     print("Happy Birthday to you!")     print("Happy Birthday to you!")     print("Happy Birthday, dear " + person + ".")     print("Happy Birthday to you!")     print("\n") #error line  happyBirthday('Emily') happyBirthday('Andre') happyBirthday('Maria') 
like image 555
Gmenfan83 Avatar asked Dec 14 '12 03:12

Gmenfan83


People also ask

What does empty print () do in Python?

It prints an empty line, just as you have said. It will leave a blank line in the output. The print statement prints its arguments, and then a newline, so this prints just a newline.

How do you print a new blank line in Python?

The new line character in Python is \n . It is used to indicate the end of a line of text. You can print strings without adding a new line with end = <character> , which <character> is the character that will be used to separate the lines.

How is a blank line represented in Python?

Before getting to this, it should be noticed that in Python the \n character represents a newline.


1 Answers

You can just do

print() 

to get an empty line.

like image 85
user3743923 Avatar answered Sep 28 '22 14:09

user3743923