2.4 Function print
and an Intro to Single- and Double-Quoted Strings
The built-in print
function displays its argument(s) as a line of text:
In [1]: print('Welcome to Python!')
Welcome to Python!
In this case, the argument 'Welcome to Python!'
is a string—a sequence of characters enclosed in single quotes ('
). Unlike when you evaluate expressions in interactive mode, the text that print
displays here is not preceded by Out[1]
. Also, print
does not display a string’s quotes, though we’ll soon show how to display quotes in strings.
You also may enclose a string in double quotes ("
), as in:
In [2]: print("Welcome to Python!")
Welcome to Python!
Python programmers generally prefer single quotes.
When print
completes its task, it positions the ...
Get Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.