print and an Intro to Single-and-Double-Quoted Strings¶print function displays its argument(s) as a line of text print('Welcome to Python!')
").print("Welcome to Python!")
print completes its task, it positions the screen cursor at the beginning of the next line. print('Welcome', 'to', 'Python!')
\) in a string is the escape character. \n represents the newline character escape sequence, which tells print to move the output cursor to the next line. print('Welcome\nto\n\nPython!')
| Escape sequence | Description |
|---|---|
\n |
Insert a newline character in a string. When the string is displayed, for each newline, move the screen cursor to the beginning of the next line. |
\t |
Insert a horizontal tab. When the string is displayed, for each tab, move the screen cursor to the next tab stop. |
\\ |
Insert a backslash character in a string. |
\" |
Insert a double quote character in a string. |
\' |
Insert a single quote character in a string. |
print('this is a longer string, so we \
split it over two lines')
\ is not the escape character because another character does not follow it.print('Sum is', 7 + 3)
©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 2 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.