Python is an object-oriented high-level programming language created by Guido van Rossum in 1991. Since then, Python has become very popular in the programming world. The most recent version of Python is Python 3, although Python 2 is still popularly used by programmers.
Python can be used for developing web applications on the server, in developing software, in performing complex mathematics, in system scripting and in handling big data.
Python works on platforms such as Linux, Windows, Mac, Raspberry Pi, etc. Python’s is very simple, and is similar to the English Language, as it was designed for readability.
Every new line is considered as a new command in Python and does not require the use of semicolons or parentheses as in other programming languages. However, indentation is very important, as Python uses indentation, instead of curly braces, to define the scope of classes, loops, and functions.
Python also allows programmers to write fewer lines of codes compared to some other programming languages. Python can be written in text editors as well as IDEs such as NetBeans, Eclipse, Pycharm, etc.
As Python is already installed in many PCs and Macs, you can search if it’s installed on your machine through the search bar, or by typing the following in Command Line (cmd.exe).
If it is not installed on your computer, download it for free from this website:
Writing Your First Program
Using Command Line:
When you want to test a small program, the quickest and easiest way is to use Command Line.
For this, type the following command in the Command Line.
After this, write any Python program, as shown below.
And then press “Enter”, and you can see the executed program as shown below.
When you have finished, you should type the following command to quit the Command Line Interface.
Whenever you are done in the python command line, you can simply type the following to quit the python command line interface:
As Python is an interpreted programming language, Python interpreter can execute Python (.py) files written in a text editor.
To run a Python file, type as following in the Command Line.
And the output will be shown as below:
Here are the contents of the HelloWorld.py file:
Now that you have written and executed a Python program!
In Python, a variable is created as you assign a value to it. There is no specific command to declare a variable or its type.
For example: If we run the following program (variable.py),
The output will be like this:
Rules for naming variables are:
- It is case sensitive ( for example, age, Age, AGE are all different variable names.
- Should with a letter or underscore.
- Cannot start with a number.
- Can only contain alphanumeric (A-Z,a-z,1-0) characters and underscores.
Python uses print statement to output variables.
To combine both variable and text, Python uses the + character, as shown in the example below:
The output is shown below:
Also, the + character can also be used to combine two variables as shown below:
If you use the + character on numbers, it will work as a mathematical operator.
The output for the above program will show as:
However, if you try + character to add a number and a string value, it will show an error.
Python is a general-purpose language which is very easy to learn yet a very powerful language. We hope this tutorial helped you in getting started with Python as it introduces you to the basic concepts which are noteworthy to be shared, and gives you a taste of its flavor and style.
If you want to get into the depths of Python, there are many sites that will cater to your interest, such as https://docs.python.org/3/tutorial/