
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
How to print to the Screen using Python?
The basic way to do output to screen is to use the print statement.
>>> print 'Hello, world' Hello, world
To print multiple things on the same line separated by spaces, use commas between them. For example:
>>> print 'Hello,', 'World' Hello, World
While neither string contained a space, a space was added by the print statement because of the comma between the two objects. Arbitrary data types can also be printed using the same print statement, For example:
>>> import os >>> print 1,0xff,0777,(1+5j),-0.999,map,sys 1 255 511 (1+5j) -0.999 <module 'os' (built-in)>
Objects can be printed on the same line without needing to be on the same line if one puts a comma at the end of a print statement:
>>> for i in range(10): ... print i, 0 1 2 3 4 5 6 7 8 9
To end the printed line with a newline, add a print statement without any objects.
for i in range(10): print i, print for i in range(10,20): print i,
The output will be:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
If the bare print statement were not present, the ouput would be on a single line.
In Python 3, all print statements arguments need to be surrounded by parenthesis. For example,
>>> print("Hello", "world") Hello world
- Related Articles
- How to clear screen using python?
- How to simulate Print screen button using selenium webdriver in Java?
- Print screen using VBA in SAP
- How to print the Fibonacci Sequence using Python?
- How to print "Hello World!" using Python?
- How to clear screen using C#?
- How to clear screen using Java?
- How to clear screen in python?
- How to print the days in a given month using Python?
- How to print current date and time using Python?
- Print shortest path to print a string on screen in C Program.
- Printing to the Screen in Python
- How to center a div on the screen using jQuery?
- How to create a Splash Screen using Tkinter?
- How to create a simple screen using Tkinter?
