How to output to console with print function
Output to console
Printing a line of text in Python.
print "Welcome to Python!"
print "Welcome",
print "to Python!"
The code above generates the following result.
Printing multiple lines with a single statement.
print "Welcome\nto\n\nPython!"
The code above generates the following result.
print accepts various data types.
letter = 'c'
print "give me a", letter, "..."
answer = 42
print "the answer is:", answer
The code above generates the following result.
A trailing comma avoids the newline after the output:
a, b = 0, 1
while b < 1000:
print b,
a, b = b, a+b
The code above generates the following result.