Java Certification Training Course
- 47k Enrolled Learners
- Live Class
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.
How do we go about writing a simple Hello World Program in the Python world? Let us take a look:
The official Site for Python downloads: https://www.python.org/download
Download Python for your Operating system.
Default Location for Python 3.4 is: C:/Python34
Alternatively you can open the Python shell from the Python Install Directory:
Now, the syntax of the actual program depends on the version of the python program being used:
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:
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’:
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!
Got a question for us? Mention them in the comments section and we will get back to you.