Python is one of the most popular and useful programming languages. Nowadays, Python is being used for creating web applications, machine learning, artificial intelligence, data analysis, and many more.
Table of Contents
What is Python?
In simple words, Python is a high-level, general-purpose, interpreted, object-oriented programming language with dynamic semantics.
The duch programmer Guido Van Rossum created Python in 1989. But python was released on Feb 20, 1991, in the public domain.
However, Python started growing after 2012. Please have look at the graph-
Reason of becoming so popular?
Easy to learn- As compared to other programming languages python syntaxes are simpler and easier to understand.
Easy to work- Concepts like machine learning and AI are very easy with python programming language. We don’t have to use lots of syntaxes for a small task in Python like in other programming languages.
Everything Available in Pyhton- No matter what you want to do you can do it using python because you can find all the library functions and resources you need to create any sort of application, be it a web application or artificial intelligence.
Biggest companies like Google, Facebook, Quora, and many more companies use Python for developing their applications.
Why and How Python is a High-Level Programming Language?
If you are from a computer science background then you should know there are three levels of programming languages.
- Low-Level Programming Languages
- Machine-Level Programming Languages
- High-Level Programming Languages
Low and machine-level programming languages are easy for computers to understand but hard for programmers. While High-Level programming languages are easy for programmers to understand and hard for computers to understand.
The computers understand 0 and 1 binary digits but python codes are written in English that’s why Python is a High-Level Programming Language.
How python is a general-purpose programming language?
Python is a general-purpose programming language because a programmer can use python for creating almost any kind of application.
Basically, Python is capable of creating any kind of program that’s the reason it is a general-purpose programming language.
Why python is known as an interpreted programming language?
It is because The bytecode interpreter interprets the python source code into bytecode and then it is executed by the Python virtual machine.
How Python is Object Oriented Programming Language?
It is because you can define classes in python to create objects just like in other object-oriented programming languages.
In Python, we don’t have to define data types and this feature is known as dynamic semantics.
Nowadays, we get Python pre-installed in almost all operating systems like, Windows, Linux, and Mac. Using a simple command you can verify if Python is already installed on your system or if you need to install it.
Command to verify if Python is already installed or not-
If you are a Linux or Mac user and getting an error like this-
Command 'python' not found
Then in such a case, run the following command to verify if Python version 3 is installed on your system-
If python is not installed on your system then download python’s latest release and install it.
Install Python on Windows
In order to install python on windows, download the python executable file from the official site.
And after downloading install it as you install other software applications on your system.
Once the installation gets finished, verify it by running
python --version command like this-
All done, now you can write and run a Python program on your Windows Computer.
Install Python on Linux (Debian Based Distributions)
If you are using Linux then there is a chance that Python or Python3 should already be installed on your system. First of all, verify it if you have not verified it.
And if it is not installed then you can install it by running the following command-
sudo apt update sudo apt install python3
It will take a few seconds and python3 will be installed on your system.
Install Python on Mac OS
If you are using Mac OS then you need to download and Install the Anaconda individual edition software application from its official site.
If you are unable to find the individual edition then you can download the suggested package from the site’s homepage.
After installing it, open it and launch the spider IDE from the anaconda in order to run the Python application.
Note: The Spider IDE will be listed in the Anaconda Navigator. If it is not available in the list then you can download it from the web.
Create Your First Program
Now it’s time to create your first python program. But also, have the option to run some basic python codes without even creating a file.
How can you run Python code without saving the file?
You can run a python program using the python or python3 command on your system terminal. But when you run a Python program in such a way the code you write doesn’t get stored anywhere and you can not reuse it.
This process is known as running python code interactively.
It is always a good practice to create a file for your python program and then run it.
Follow the steps to create a Python program-
Step 1: Open a text editor.
Step 2: Write the program in the text editor.
Step 3: Save the program with
.py file extension. For example, if you are creating a “Hello, World!” program then you can save the file with
.py extension like “HelloWorld.py”.
Run a Python Program
This is the most common question asked by beginners. If we talk about running a Python program then we have three options to run it.
- Using an IDE
- Using Command Line Tool (Run Interactively)
- Executing .py program file.
Run Python Program Using IDE- You can use an IDE to write and run a Python program. Pycharm is one of the most popular IDE for Python programming.
However, we can use lightweight IDEs also like Microsoft’s VS Code (Visual Studio Code).
In IDE (Integrated Development Environment), you will find a run option to run the program.
Here, we are using VS Code for the example. Well, in VS code, we can find the run option in the menu bar.
You can debug and run (F5) Python programs or run without debugging (CTRL+F5) in IDEs.
Note: In order to use, Python in VS Code you will have to install the Python plugin in it.
Run Python Program Using Command Line Interface- We can write and run a Python program in the command line also.
In order to do so, open your command-line interface on your system. And then run the python or Python3 command as per the installed version.
After running the command, the Python interpreter will get open in the immediate mode where you can write and run the programs. But keep this in mind, when you write Python programs using the command-line interface your code doesn’t get saved anywhere. You will not be able to reuse the code again.
Have a look at the Image-
Once you are done writing code then you can simply exit from here using the
.py Program File- As we know that we can save Python program files with a .py extension. So, we can execute it also whenever we need to execute it.
In order to execute python programs we use the command line or terminal and use one of the following commands as per the installed version.
If both versions are installed on your system then both commands will work. Otherwise, It will work as per the installed version only.
Suppose, We have created a first.py program on our desktop then we will use the following command to the program-
Here, The Desktop is the path of the file and first.py is the file name.
Here in this tutorial, we learned some basic things about Python like Installing Python, Creating the first program, and running it.
Next Topic: Since this topic is part of the complete Python course so our next topic is Data Types in Python.