- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Print Hello world
Let us try to execute Python “Hello World” programs in different modes of Python programming.
Interactive Mode Programming
Example
Invoking the interpreter without passing a script file as a parameter brings up the following prompt −
$ python Python 2.4.3 (#1, Nov 11 2010, 13:34:43) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Output
Type the following text at the Python prompt and press the Enter −
>>> print "Hello, Python!"
Example
If you are running new version of Python, then you would need to use print statement with parenthesis as in print ("Hello, Python!");. However in Python version 2.4.3, this produces the following result −
Hello, Python!
Script Mode Programming
Invoking the interpreter with a script parameter begins execution of the script and continues until the script is finished. When the script is finished, the interpreter is no longer active.
Example
Let us write a simple Python program in a script. Python files have extension .py. Type the following source code in a test.py file −
print "Hello, Python!"
We assume that you have Python interpreter set in PATH variable. Now, try to run this program as follows −
$ python test.py
Output
This produces the following result −
Hello, Python!
Example
Let us try another way to execute a Python script. Here is the modified test.py file −
#!/usr/bin/python print "Hello, Python!"
We assume that you have Python interpreter available in /usr/bin directory. Now, try to run this program as follows −
$ chmod +x test.py # This is to make file executable $./test.py
Output
This produces the following result −
Hello, Python!
- Related Articles
- How to print "Hello World!" using Python?
- C Program to print “Hello World!” without using a semicolon
- C++ "Hello, World!" Program
- Print Hello World without semicolon in C++
- Creating Java Hello World Program
- Hello World Program in Java
- Hello World program in Kotlin
- Analysis of Java "Hello World" Program
- How to write "Hello, World!" program in JavaScript?
- How to write "Hello World" Program in C++?
- How to write first Hello World program using CGI programming in Python?
- Internal Analysis of Java "Hello World" Program
- Print “Hello World” with empty or blank main in C++
- Print “Hello World” without using any header file in C
- Print “Hello World” in C/C++ without using header files
