Pages

Footer Pages

Spring Boot

Java String API

Java Conversions

Kotlin Programs

Kotlin Conversions

Java Threads Tutorial

Java 8 Tutorial

Friday, May 15, 2020

Python Program to Print Hello world!

1. Introduction


In this tutorial, You'll learn a beginner's Python program to print Hello World program. The example program can be executed from python IDE or shell prompt.

You can download the latest python version from the official website here.

You no need prior experience or knowledge on the python concepts. Because this is the first program for beginners. So, You'll get the basics of python scripting here.

Python Program to Print Hello world!-min

Print hello world! in Python Programming




2. Python 2. 7 Program to Print Hello World


Let us start writing the first python program now.

Open the terminal from mac and then python command that opens a python prompt or python IDE from a windows machine.

$ python
WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Feb 29 2020, 01:55:37) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> pring ('hello world')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pring' is not defined
>>> print ('hello world')
hello world
>>> 

Python JSON Type Error 

From the python prompt, type print() method and pass the String "Hello World" that prints the output to console.

If you mistype the print() method as pring then it will show the NameError for "pring" is not defined. Hence, must be careful while using built-in methods of any programming language.

3. Python 3 Hello World Program


The above program is executed from python 2.7 version. Now let us type "python3" from the terminal.

$ python3
Python 3.7.7 (default, Mar 10 2020, 15:43:03) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'Hello World'
  File "<stdin>", line 1
    print 'Hello World'
                      ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello World')?
>>> print 'Hello World';
  File "<stdin>", line 1
    print 'Hello World';
                      ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello World')?
>>> print ('Hello World');
Hello World
>> 
You should wrap the text inside the string either using single or double-quotes. Both will produce the same output.

The string is a set of characters that must be enclosed in single, double, or triple quotes.


4. Hello World Programs in Other Languages


We've shown the same to print Hello World in different languages as follows.

Kotlin Hello World Program
Java Hello World Program
Spring Boot Rest API Hello World Example

5. Conclusion


In this article, You've seen how to print the hello world in python programming. Examples are shown with python 2.7 and 3 versions and both are produced the same output.

Use the print() function to print any content to the console.

No comments:

Post a Comment

Please do not add any spam links in the comments section.