Hello, World! in Python
This article is tutorial which teaches you how to print "Hello World!" In python.
In python we use
There are various versions of python available till date. We are going to use the latest version python 3.7.2 in this and rest of the tutorials.
In python 2 the
Syntax of
Print "Hello World!" message to the console in Python
In many programming languages we use keywords like print, printf etc to print / display something on the console (screen).In python we use
print()
function to display some message to console.There are various versions of python available till date. We are going to use the latest version python 3.7.2 in this and rest of the tutorials.
In python 2 the
print
directive is not a function so we do not include the message in parenthesis but in python 3 and further versions print
is a function so we need to include parenthesis. Please refer to python installation and environment setup for instructions on how to install and setup python in your system. My suggestion to you is to use online compiler for this tutorial if are facing issues with installing and setting up the environment.Syntax of print()
in Python:
print(object(s), separator=separator, end=end, file=file, flush=flush)
print()
Parameters Explained
Parameter | Description |
---|---|
object(s) | Any object, and as many as you like. Will be converted to string before printed. |
sep='separator' | Optional. Specify how to separate the objects, if there is more than one. Default is ' ' |
end='end' | Optional. Specify what to print at the end. Default is '\n' (line feed). |
file | Optional. An object with a write method. Default is sys.stdout |
flush | Optional. A Boolean, specifying if the output is flushed (True) or buffered (False). Default is False |
Python Code to Print "Hello World!"
print("Message in double quotes gets displayed.");
Output:
Message in double quotes gets displayed.
Example:
By using above syntax of print function in python we can easily print Hello World to the screen.
print("Hello World !, I am learning Python");
Compile the program using following syntax (for Linux users)
python myprogram.pyNow run the program using following syntax
./myprogram.py
Output:
Hello World !, I am learning Python