blog posts

Tutorial On Python Programming Language In Simple Language

Part 1: Install Python Interpreter on Windows, Linux, and GNU/Linux

To install the Python programming language, you must first download the desired version from the Python website. When you select the Downloads option, as shown below, a new section will open, allowing you to download Python based on your operating System type (Windows, Mac, Linux, etc.).

In the category of Education, the Python programming language is with you.

There are different versions of Python, and notable differences exist between Python 2 and Python 3. Here, we will teach Python 3.8.1, as recommended by Python creator Guido van Rossum, the latest version of Python that has just been released.

Step-by-step tutorial on Python programming language in simple language

Note that the version in question cannot be installed on Windows XP. To install Python on Linux, the terminal instructions inside Linux will be used for installation, which we will discuss in the installation section on Linux and GNU (if you want to download the File directly from the site, in the Source Code section, you can download the File you wish to)

The version displayed on the first page is for the 32-bit version of Python. If your Windows operating System is 64-bit, please visit the Windows page and download the desired version.

On macOS, for Python version 3.8.1, only the 64-bit version can be downloaded. For the 32-bit version, you can download version 3.7.6.

Install Python Interpreter on Windows

We will first install the version compatible with the Windows operating System. After downloading the desired version, run the downloaded File to open the following page. We download and install the 64-bit version here. There is no significant difference in the performance of the two versions.

Learn Python programming language

Part 1

This recommended section, which can be accessed by clicking on it, includes all the required Python packages, along with their documentation. If you are new to the Python programming language, this option is recommended for you.

part 2

Within this section, you can select the items installed by Section 1 that you do not intend to install, and you can also change the default installation location.

Part 3

In this section, you have two options to choose from. The first option is for the case where you have multiple users on your Windows System, and by checking this section, you notify the program to install Python for all users.
The second option provides easier access to Python, particularly for installing packages and using it in Windows CMD. It is recommended that you review this section as well, so you do not encounter problems in the subsequent sections.

Here, we select part 1 and proceed to the next step.

After the installation is successful, the following image will be displayed. If you are presented with an option called ‘Disable Path Length Limit, click on it to add the Python installation path to the Windows path for improved access.

Introduction to Python programming language training

To check if the Python programming language is installed correctly on the operating System, type cmd in the search field at the bottom of the window menu and click on Command Prompt. If you are using Windows 10, you should see a similar image below:

How to learn Python programming language

After clicking on CMD, the following image will open.

How to learn Python programming language

Here we can see the version of Python installed on the operating System using the following Command.

<span style="font-size: 16px;">python –version</span>

Take a look at learning Python programming language

Install the Python Interpreter on Linux to learn the Python programming language.

Sometimes, Python is installed by default on certain Linux and GNU versions. To check this, first enter the following commands in the terminal:

If some value is not returned, it means that Python is not installed on your operating System.

Installing Python on Linux or GNU is very simple and requires running two commands.

The first Command is for apt-get Update, which you can do with the following Command:

The second Command is to install the desired version of Python using apt-get, which is as follows:

After running these two commands, using the commands mentioned at the beginning, you can verify that Python and the installed version are installed correctly.
In this section, we successfully installed our desired version of Python on our operating System. In the next section, we enter the Python programming space.

Part 2: Teaching Python Programming Language: Familiarity with Python environments

You can code in different environments with Python. From the various IDEs (IDEs are programs that you can code) to Windows cmd and the Linux terminal and Python IDLE itself, you can easily code in all of these environments.

Windows CMD Coding (Linux terminal)

First, we see an example of Coding in the Windows Command Prompt space. To do this, and if you have added the Python installation path to the Windows path, you can enter the Python Coding space using the Python Command. If you have done the steps correctly, you will see a space similar to the space in the photo below:

Part 2 of the Python programming language tutorial

To get started and to write the first Command line in Python, we will print a phrase using the print Command. The phrase to print is:

<span style="font-size: 16px;">Print(‘hello Python’)</span>

After executing the Command, the output of the program will be similar to the following image:

 Step-by-step tutorial on the Python programming language

We are now able to execute the first Command from the Python programming language easily. In Linux, similar to Windows, you can enter the Python environment and then type the same Command to view the same output.

Note that when you enter the Python space, you will first see the phrase >>> for each line of Coding.

To view other environments, we will run the same Command in different environments.

Coding in Python IDLE space

The next environment to work in is the IDLE space for Python itself, which will be installed along with Python on the Windows operating System. You can view the IDLE (Python GUI) program by using the Windows search box and typing Python.

Coding in Python IDLE space

After executing the program, we will re-execute the Command from the previous part, and you will see the desired output, which is similar to that of the prior part.

Coding in Python IDLE space

If you have several versions of Python installed on your operating System, you must open the IDLE corresponding to the desired version, which, as shown in the image above, first displays the type of Python version you want.

As you can see, the primary difference between IDLE and CMD is that IDLE offers a more visually appealing and aesthetically pleasing Python environment.
In this environment, according to the type of commands and their features, different colors have been used, which has also significantly increased the readability of the code compared to using CMD.
Using this environment is not the preferred option for teaching the Python programming language in this series of articles. However, for those who want to know the meaning of each color, we have defined it here.

Learn Python programming language in simple language

Red

This color is used in two cases:

To write a comment: A comment is a phrase that we add inside ourselves for higher readability and does not affect the output of our code. Sometimes multiple programmers may work on the same code, or you may have a function that has a specific purpose, in which case using a comment will make you a better, more professional programmer.

When you mistype a Command and you get an error.

Purple

These colors are used to display functions and commands that are defined by default in Python. For example, the print Command is a built-in function in Python that has a specific purpose.

Green

This color is used to display values in the form of strings. We’ll talk about strings in more detail later, but the expressions inside “” are called strings.

Orange

This color will be seen when you use a Python keyword; these words are defined by default in the Python language. For example, the use of loops and conditional statements, such as ‘if’ and ‘for’, are among the items considered Python keywords and are displayed in this color.

Blue

This color is used in two places:

  • When output. For example, the output value of the printCommand is displayed in blue here.
  • To specify the names of functions or classes. We will talk about classes and functions later.

Black: This color is used for the values ​​that Python receives as input or defines as a variable.

The key point to note is that these colors are the default mode in P hon IDL can. You can use the following desired.

Options -> configure IDLE -> Highlights

Coding in Visual Studio Code space

The last space we will discuss is the Visual Studio Code space, commonly referred to as VS Code. This IDE is one of the most popular Coding IDEs. After installing and running the program, you will see the following page:

Coding in Visual Studio Code space

Note that the .py extension is associated with Python files, and you should save them with this extension. If you are opening this software for the first time, create a new File from the path below. After saving the File, save it in .py Format so that the IDE recognizes the Python language for your Coding space.

File -> New File

Extension capability

This IDE has a feature called extensions that you can use to install plugins to provide a better Coding environment. We also want to install these plugins for Python. According to the figure below, click on the extension to view a page similar to the one shown in the image below. Then, in the search field, type Python to display the Python plugins.

Coding in Visual Studio Code space

It is recommended that you install the two plugins specified. Next to the names of the plugins on the right, you can see the number of installations and points each plugin has received. If you click on a plugin, you can view its detailed Information.

After clicking ‘Install’ and the installation is complete, you need to reload VS Code once to install the plugin, similar to the image above. Now, we execute our Command. After executing the Command, the output is visible at the bottom of the page.

Python programming environments

Note that Python is a language that is case sensitive, meaning that uppercase and lowercase letters have different meanings and are sensitive to it. For example, if you type the print() Command as Print(), Python does not recognize it. “For Python’s default functions and words, it must be spelled in uppercase and lowercase.”

Python Programming Environments

In this article, you will learn about different programmable environments in Python. Other environments are also suitable options for Python. However, in the Python programming language tutorial, we will run commands within the VS Code environment. If you are interested, you can also run commands on other environments. In the following article, we will look at the types of variables that can be defined in Python.

Part 3: Teaching Python Programming Language: Types of Data in Python

In the Python programming language, there are a variety of variables, including integers, decimals, strings, arrays, and so on. In this section, we are going to explain each of these in full. In programming languages, the types of variables are referred to as data types.
So, if you are asked in an interview or conversation what Data Types are in Python or any other programming language, know what they mean by the variables available in the programming language. The types of data available in the Python programming language are as follows:

  • Numeric Type
  • Text type
  •  Boolean Type
  • Sequence Type
  • Binary Type
  • Mapping Type
  • Set Type

“Translating some terms and definitions into Persian is sometimes not appropriate in programming. It is recommended that you learn and use English phrases as much as you can.”

We will first define the variable and then determine the types of numerical data available in the Python programming language.

Variables in Python

Variables are parameters that can take a value from any data. For example, in the following Command, “a is a variable with a numeric value of 4, and “b” is another variable with a text value of “maktabkhooneh”.

There is a special Rule for naming variables in Python, and the following are unacceptable for naming variables in Python:

  1. Python keywords cannot be defined as variables. Such as if, for example, or a list,…
  2. Variables in Python cannot start with a number. 2myvar cannot be a variable name.
  3. It is not possible to use – or spaces in the names of variables. My var or my-var cannot be a variable name.

If the above three items are met, variable naming is acceptable.

You can separate the three variables in a line using a comma (,) and assign a value to them, similar to the following code:

You can assign a value to several variables:

Variables can be defined in different types of data. Variables have global and local types, which we will discuss in the topic of functions.

Numeric Types in Python Programming Tutorial

In the mathematical literature, we encounter a wide range of numbers. Natural numbers, integers, decimal numbers, real numbers, and different types of intervals that have their numbers and definitions.
In the Python programming language, there are several classifications for numbers, including:

  • Correct type (int)
  • Decimal type (float)
  • Complex type

Integer type numbers

We start with integer numbers. The range of these numbers is similar to that of integers in the mathematical definition, i.e., from positive infinity to negative infinity. Non-decimal numbers include the integer type in the Python programming language.

Decimal type numbers

Decimal-type numbers are numbers that are similar to integers, from negative to infinite to positive infinite, except that they also include decimal numbers. Depending on the type of Command and the definition used, we will discuss it later. By default, this Command displays up to 17 decimal places.

complex numbers

Complex numbers are also a type of number. In addition to the real value part, they also contain imaginary values. These numbers form a group that, when raised to the power of 2, unlike real numbers, will yield a result that is a negative number.
Additionally, the square root of negative numbers yields a complex number. Real numbers are a kind of complex number whose imaginary part is zero.

These numbers are displayed as follows:

Where a is the real value and b is the imaginary value.

We will now examine an example of numeric types in the Python programming language tutorial. Consider six different types of variables:

These numbers are integers (int), decimals (float), and complex (respectively). To view the type of these numbers in the Python programming language, we use the type() function. All you need to do to figure out the type of data you want is to type the value in parentheses in the type function. As follows:

When you run these commands, you will get the following outputs:

You will see the following image by executing the items mentioned in Python:

The concept of class in teaching Python programming language

The concept of class in teaching the Python programming language

We will discuss the idea of class in more detail before introducing the data type in the output.

Now, suppose we want to convert a decimal value to an integer value. As in a code, we have received a variable that has been a decimal, but for the US, only the integer value is essential.
One method that can be used to address this Problem is to convert the decimal type to the correct type. The Command used for this is as follows:

In this case, when you print the variable h in the output using the print () Command, it will print only its correct value, the number 1. Now, suppose we want to convert the proper value to decimals. To do this, use the following Command:

The output will be 4.0, which will be a decimal value or float. To ensure this, you can check this with the type () Command. Similarly, the complex statement can be used to convert a number to a complex value.

The conversions mentioned above are used as needed in the code. One of the applications of String conversion is when converting a number from text to a numeric type, which we will see in the next section, which deals with text type.”

You can apply different mathematical operations to any of the above types.

Text Types

This type of data is called textual expressions that are used as strings. You saw an example of this type of data when you first started working with Python. Strings in Python have various functions, each of which we will define and use here.

Special characters in strings

In the table below, we will define the characters that have a specific meaning and corresponding value.

Functions and methods in strings

In the table below, we would like to introduce you to the various functions and methods in the disciplines and their effects. The process of using the methods is as follows.

A parameter or input value in methods and functions refers to the values and variables that are specified in parentheses preceding the technique. This is one of the features that exist in classes and functions. If you want to give multiple inputs to the function, just put a comma (,) after each parameter. The order in which the input parameters are placed is essential.”

As you can see, some commands are not used in Persian, so if you are coding in PCoding, you will not need to use some of these commands.

To better understand the commands, Try each Command and see its output. Some commands are used in specific cases, and it is rare for you to use them.

All the mentioned methods and functions do not change the main String and only return new values. This means that if you run any of the above methods and functions on a String, the original String will not change, and if you want to have a new value, you will have to save it in a new variable, or if you want to make changes to If the main String is created, you must save the method output and functions again inside the primary String variable.”