Write and Execute First Python Hello World Program
Writing and executing a first hello world program is the starting point to learn any new programming language. So, If you are a Python learner then Python Hello World program is a basic step before going to master other python core concepts.
The hello world program in Python would make the developer comfortable and confident that he/she can learn with the self-learning tool.
Python has dominated the modern world of scripting languages and used in almost every concept – AI, Machine Learning and Big Data Analytics. Due to the robust set of features, Python programming language has entered the complete dimension of data analytics, Artificial Intelligence, Machine Learning, and much more. We will discuss python script to print hello world.
A few years back…When we started our career as C developer, we executed the first hello world program and realized that now we can do anything..with self-learning 🙂
Seriously, the hello world program introduces the new developer to the new system, language and opens his/her doors towards learning.
Even if you are learning core Python, AI, Machine Learning or Big Data, writing and executing a Python Hello world program is the first most, fundamental, and practical step towards learning Python. Every computer programmer improving his skills to learn new languages/technologies like Python, etc..
What is Python?
Python is a modern high-level general-purpose programming language, sometimes known as a scripting language.
Python is open-source so it has a very active python developers community. Python is automatically included with Linux OS distributions, Macintosh computers. It has millions of user base. Python programs can search for files and directory trees, launch other programs, do parallel processing with processes and threads, and so on.
The extension of the python source code file is .py.
How to check the currently installed version of Python on Windows?
- Open the command prompt
- Make sure that Python executable path is set in the PATH environment variable.
- Run the following command python -V
Besides individual developers, Python is used by top major companies for various purposes:
1. Google makes extensive use of Python in its web search systems
2. YouTube makes use of Python in the video-sharing service.
3. The Dropbox storage service codes both its server and desktop client software primarily in Python.
4. The widespread BitTorrent peer-to-peer file-sharing system began its life as a Python program.
5. Maya, a powerful integrated 3D modeling and animation system, provides a Python scripting API.
6. JPMorgan Chase, UBS, Getco, and Citadel apply Python to financial market forecasting.
Writing the first Python hello world program
To write the Python hello world program, you can make use of any text editor Notepad++, IDE or Command-line editor (vi in Linux):
- Create a new file called helloworld.py.
- Open the file and write the following code:
print(“Hello, World in Python!”)
3. Finished writing – save and close the file.
Before running the program lets first understand the basics of Python hello world program…
Internally, how does the python program works under the hood?
First of all, the Python interpreter parses, analyzes the source code contained in the .py file. The .py is the extension of the Python script/program which contains all the source code lines.
Here, print() is a function to display the given input string to the user. The string part is “Hello World”. A string in computer programming is basically a sequence of characters having null-terminated character, i.e where the compiler/interpreter knows where the string terminates.
The print() is a built-in function provided by the Python standard library for displaying strings.
Also, read Laravel Framework Tutorials:
- Laravel Framework Overview
- Laravel Request Lifecycle
- Top 20 Laravel Artisan Commands
- Understanding Laravel Middleware
- Laravel Routing Tutorial
- Understanding Laravel Blade Template
- Laravel Interview Questions
- Laravel Authentication
- Laravel Validation Tutorial
Executing Python Hello World Program
This is a very important step to understand how to execute or run a program in python. Once you have finished writing python source code in helloworld.py file, open the command prompt.
Note: We have used the Windows platform throughout this tutorial, but the concepts remain the same for all non-windows platforms also.
Make sure that python executable in already installed and added to the system PATH environment variable. Otherwise, you may get the following error:
” ‘python’ is not recognized as an internal or external command, operable program or batch file.”
Steps to execute python hello world program:
Step1: Open the command prompt:
Step2: You can execute the python script in two ways:
1. From Windows command prompt
python helloworld.py or helloworld.py
2. Open the Python command shell – “py” in the windows search bar and open command shell or open windows command prompt and type python.
Alternatively, Run Python code from Python Command shell.
Now write the source code statements and shown below and press enter. This method will also show you the same results.
print(“Hello, World in Python!”);
Both of these methods output the same results.
Step3: Observe the results on the command prompt: