Python is a widely-used programming language. It:

High Level: Python automates low-level operations like memory management. This leaves the programmer with less control but has many advantages, including code readability and minimal code expressions.

Versatile: Python is built for use in all contexts and environments. An example of a common language is PHP: it is specifically designed as a scripting language for server-side web development.

Dynamically typed: every variable in Python can refer to any data type. One expression can evaluate data of different types at different times. In this regard, the following code is possible:

if something:

    x = 1
else:
    x = 'this is a string'
print(x)

Heavily typed: During program execution, you are not allowed to do anything that is incompatible with the type of data you are working with. For example, there are no hidden conversions from strings to numbers; a string made of numbers will never count as a number unless you explicitly solve it:

1 + '1'  # raises an error
1 + int('1')  # results with 2

Beginner-friendly: Python syntax and structure is very intuitive. It is high-level and provides constructs for writing clear programs at both small and large scales. It has a large, comprehensive standard library and many easy to install third-party libraries.

Its design principles are laid out in Zen of Python.

There are currently two major Python release branches with some significant differences. Python 2.x is a legacy version, although it is still widely used. Python 3.x creates a set of backward-incompatible changes that are designed to reduce duplication of functionality. To help you decide which version is best for you, see this article.

The Official Python Documentation is also a comprehensive and helpful resource containing documentation for all Python versions, as well as tutorials to help you get started.

There is one official implementation of the language provided by Python.org, commonly called CPython, and several alternative implementations of the language on other runtime platforms. These include IronPython (running Python on the .NET platform), Jython (in the Java runtime), and PyPy (a Python implementation in a subset itself).

Starting out

Python is a widely used high-level general-purpose programming language created by Guido van Rossum and first released in 1991. It has a large and comprehensive standard library.

There are two major versions of Python currently in active use:

Python 3.x is the current version and is under active development.

Python 2.x is deprecated and will only receive security updates through 2020. There will be no new features. Note that many projects are still using Python 2, although migrating to Python 3 is getting easier.

You can download and install either version of Python here. See Python 3 and Python 2 for a comparison between the two. Additionally, some third-party vendors offer repackaged versions of Python that add commonly used libraries and other functionality to make it easier to customize for general use cases such as math, data analysis, or scientific use. See the list on the official website.

Check if Python is installed

To make sure Python is installed correctly, you can verify that by running the following command in your favorite terminal (if you are using Windows OS, you need to add the python path to your environment variable before using it on the command line.

$ python --version
Python 3.x 3.0
If you have Python 3 installed, and this is your default version 
$ python --version
Python 3.6.0
Python 2.x 2.7

If you have installed Python 2, and it is your default version

$ python --version
Python 2.7.13

If you’ve installed Python 3, but it $ python –version prints out Python 2, you also have Python 2. This is common on macOS and many Linux distributions. $ python3use this $ python3to explicitly use the Python 3 interpreter.

Hello world in Python using IDLE

IDLE is a simple Python editor that ships with Python.

How to create a Hello World program in IDLE

Open IDLE on your system of choice.

On older versions of Windows, it can be found under the All Programs”Windows menu” section.

On Windows 8+, search IDLEor search for it in the applications present on your system.

On Unix based systems (including Mac), you can open it from the shell by typing $ idle python_file.py.

It will open a shell with options at the top.

The shell has a hint of three square brackets:

>>>

Now write the following code in the tooltip:

>>> print("Hello, World")

Click Enter.

>>> print("Hello, World")
Hello, World

Hello World Python File

Create a new file hello.pythat contains the following line:

Python 3.x 3.0

print('Hello, World')

Python 2.x 2.6

You can use printPython 3 function in Python 2 with the following statement import:

from __future__ import print_function

Python 2 has a number of functions that can be imported from Python 3 from a __future__module __future__, as described here .

Python 2.x 2.7

If you are using Python 2, you can also enter the line below.

print 'Hello, World'

In your terminal, change to the directory containing the file hello.py.

Enter python hello.py, then press Enter.

$ python hello.py
Hello, World

You should see it Hello, Worldprinted on the console.

You can also replace hello.pywith your file path. For example, if you have a file in your home directory and your user is “user” in Linux, you can enter python /home/user/hello.py.

Leave a Reply

Your email address will not be published. Required fields are marked *