GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 11 von 20 · Text

The print() function - the escape and newline characters 1

David Khieu

The print() function - the escape and newline characters

We've modified the code again. Look at it carefully. 

There are two very subtle changes - we've inserted a strange pair of characters inside the rhyme. They look like this: \n. 

Interestingly, while you can see two characters, Python sees one. 

the backslash (\_ has a very special meaning when used inside strings - this is called the escape character.

The word escape should be understood specifically - it means that the series of characters in the string escapes for the moment (a very short moment) to introduce a special inclusion. 

In other words, the backslash doesn't mean anything in itself, but is only a kind of announcement, that the next character after the backslash has a different meaning too. 

The letter n placed after the backslash comes from the word newline.

Both the backslash and the n form a special symbol named a newline character, which urges the console to start a new output line

Run the code. Your console should now look like this: 

As you can see, two newlines appear in the nursery rhyme, the places where the \n have been used. 

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck