Use Python on Linux. A good way to learn programming.

Using Python on Linux is an excellent idea if you want to learn to program

Although some of the best integrated development environments for Python are available in Linux, you can also use your distribution's text editor.

Using Python on Linux is one easy and fun way to get started in programming. What tribute to Guido Van Rossum, the creator of this popular programming language, let's see how to configure a Python programming environment on our Linux distribution.

Why use Python on Linux?

Python is an easy-to-learn programming language. It has a huge base of documentation in our language (much of it free) and can be used both for creating small terminal applications or large projects with a graphical interface.

The code developed in Python can be used on Linux, Windows, Mac, Android and on different types of devices like smart TVs and GPS.

Qpython3 app for writing and executing Python code on Android

With the app Qpython3 we can write and run Python 3 code on our Android device.

Starting to use Python

Since most (if not all) Linux distributions They come prepared to use Python, the first thing is to check the version that we have installed. At this time, branch 2 and branch 3 coexist. However, branch 2 will disappear in 2020.

We can check the version we are using with the command
python --version
If you are using a relatively new distribution, you may get an error message. If so try this:
python3 --version
If you used the first command and the version number starts with 2, try the second command to see if you have Python 3 installed.

If you don't have a version, look for Python in your distribution's software manager to install it.

As well it is recommended to install Pip.Pip is the acronym for Pip Installs Packages, a package manager that will make it easier for you to get libraries for Python.

In Debian and derivatives you can do it with the command
sudo apt install python3-pip

In other distributions it simply looks for python3-pip in the package manager

Python interpreter in terminal

By typing the command python3 in the Linux terminal, we can open the python interpreter and run short programs.

Let's test the code.
In the terminal type:
python3
print("Linux Adictos")

Let's do some math
print (20*5)
Note that since it does not have quotes, what is printed is the result. Instead, if we do:
print ("20*5)
We will see what we put in parentheses.
We can use variables.
Type in the terminal.

a=20
b=10
print (a*b)

It is also possible to do this with words. We just have to add quotes.
blog="Linux Adictos"
print("El mejor blog sobre Linux es ", blog)

Now let's work with data entered by us.
In the terminal we write:
numero1=input("Ingrese un número: ")
Pressing Enter will ask us to enter a number. After doing it and pressing Enter, we type:
numero2=input("Ingrese otro número: )
We press Enter, we write the other number and we press Enter again.
Now write;
print (number1 + number2)

Writing longer programs

You may have noticed that using the terminal it is impossible to write long programs. In fact, there are several integrated development environments that make it easy to write Python code. Isaac commented some of them in this article. However, for the purposes of this article we are going to settle for the text editor.

If you still have the terminal open, close it. Now open the text editor of your distribution and write.
blog="Linux Adictos"
nombre=input("¿Cuál es tu nombre: ?")
print(nombre, "cree que", blog, "es el mejor blog sobre Linux")

Save it in your personal folder with the name test.py.

Open terminal and type
python3 prueba.py

VS Codium

VSCodium is an integrated development environment

VSCodium Integrated Development Environment uses Visual Studio Code source code

As I said above, there are many integrated development environment options that you can use to create code in Linux. In my opinion, the best alternative is VSCodium.

VSCodium is built on the source code of Visual Studio Code, MIcrosoft's integrated development environment. The difference is that it compiles without any of the tracking tools that the company adds to it. The program can be used on Windows, Linux and Mac and downloaded from here:

Once installed, from the extensions menu, install the extension Python.


Leave a Comment

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

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Gregory ros said

    I haven't programmed for too many years, out of curiosity I read about such and such languages, their improvements and news. I was surprised / surprised by the power of Python and how easy it is to learn, it is clear that if one day I return to Python programming it is the candidate for such. It is not uncommon for me to read surveys and see that it is the preferred language of developers. It is also clear that according to what tasks there are other languages ​​such as C / C ++ that shine for this purpose, but considering language for "generic" use, or to start, today it is king.

    1.    Diego German Gonzalez said

      At least it does not generate the hatred that for example Java generates

      1.    Gregory ros said

        I am particularly one of those who do not like Java, it is not hatred, nor mania, or anything like that, I did not see any justifiable reason for its creation. As an interpreted language they already had Python eg, it is also multiplatform, with high-level syntax and also open and free, I just saw it more as a Sun Microsystems maneuver, hopefully, than as something practical, personal opinion only. But I don't think it's hate, only that compared to Java it loses many points, the only thing that puts it in a leading position is the support of the greats.

  2.   Yo said

    wow I'm just seeing how to set it pip, thank you very much!

  3.   michael salazar said

    Thank you, this article was very useful.