Python For Beginners - Writing Your First Python Program

About

One of the primary lessons for any beginner in Programming is the ‘Hello World’ program. Here, we will see how the ‘Hello World’ Program is executed and also get you started with what Python is all about. To master Python you need to work with real-world case studies & this blog is a stepping stone towards it.

Python is a general purpose interpreted, high-level and object-oriented programming language. This language is easy to learn, read and maintain. It is also portable and is often called a beginners’ language. It supports almost every operating system and is quite a simple language.  Python has a very straightforward syntax, while encouraging programmers to program without boilerplate (prepared) code.

The simplest directive in Python is the “print” directive – it simply prints out a line (and also includes a newline, unlike in C). There are two major Python versions, Python 2 and Python 3. Python 2 and 3 are quite different. This tutorial uses Python 2, because it is more widely used and supported. However, Python 3 is more semantically correct, and supports newer features.

Learn More

Python : Hello World Program

How do we go about writing a simple Hello World Program in the Python world? Let us take a look:

Step 1: Download Python

Python 101 - Hello World Program
Python 101 - Hello World Program

Download Python for your Operating system.

Step 2: Install Python 

Python 101 - Hello World Program
Python 101 - Hello World Program
Python 101 - Hello World Program

Step 3: Go To Python Install directory (Cmd)

Python 101 - Hello World Program

Default Location for Python 3.4 is: C:/Python34

Course Curriculum

Python Scripting Certification Training

  • Self-Paced Learning
  • Real-life Case Studies
  • Assignments
  • Lifetime Access

Explore Curriculum

Python 101 - Hello World Program

Alternatively you can open the Python shell from the Python Install Directory:

Step 4: Hello World Program

Now, the syntax of the actual program depends on the version of the python program being used:

Python 101 - Hello World Program

On the command Line, write the Python code:  print (“Hello World”) and push Enter. Python will automatically echo the Output to screen.

Alternatively, if one wants to execute Python code post, saving the code in a file here is what one can do:

Start up your favorite editor and save the following into a file:

 print "Hello, World!"

To execute this program, save it with a suffix of ‘.py’ (e.g., HelloWorld.py) and type ‘python’ and the filename in a shell like this:

 > python HelloWorld.py

The output is predictable:

Python 101 - Hello World Program

Hello, World!

If you prefer to execute it by its name, instead of as argument to the Python interpreter, put a “bang” line at the top. Include the following on the first line of the program, substituting the absolute path to the Python interpreter for /’path/to/python’:

#!/path/to/python

Be sure to change the permission on the file to allow execution, if necessary for your operating system.

We hope this helps you give a kick start to Learning Python!

Related Courses – Learn Online Now

RPA (Robotic Process Automation)

Machine Learning with 9 Practical Applications

Mastering Python – Machine Learning

Data Sciences with Python Machine Learning 

Data Sciences Specialization
Diploma in Big Data Analytics

Learn Internet of Things (IoT) Programming
Oracle BI – Create Analyses and Dashboards
Microsoft Power BI with Advance Excel

Join FREE – Big Data Workshop 

sharing is caring