Python-Powered DevOps

Python-Powered DevOps

✅️Introduction

In this article, we will learn how to install Python on the Linux operating system and Data Types in Python.

✅️Task01:Install Python latest on the Linux operating system

The following steps explain how to compile Python 3.11 from the source:

Step1:Open a Terminal: open a terminal in Ubuntu by searching for "Terminal" in the applications menu or by using the keyboard shortcut Ctrl + Alt + T.

Step2:Update Package List: Enter the following command to update the package list:

sudo apt update

Step3:Install Prerequisites: Some prerequisites are required for building and installing Python from source. You can install them using the following command:

sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev

Step4:Download the Latest Python: Check the official Python website (python.org/downloads) to find the latest version available. Replace the URL in the command below with the URL of the latest version:

wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz

Step5:Extract the Downloaded File: Use the following command to extract the downloaded tarball:

tar -xf Python-3.11.4.tgz

Step6:Navigate to the Python Directory: Navigate into the extracted directory:

cd Python-3.11.4

Step7:Configure and Install: Run the configure script to prepare the build:

./configure --enable-optimizations

Step8:start the build and installation process:

make -j 12
sudo make altinstall

Step9:Check Python Version: After installation, you can check if Python 3.11.4(or the version you installed) is available by running:

python3.11 --version

✅️Task02:Data Types in Python

  1. Numeric Types:

    • int: Integer data type for whole numbers (e.g., 5, -10).

    • float: Floating-point data type for decimal numbers with fractional parts (e.g., 3.14, -0.5).

    • complex: Complex number data type with real and imaginary parts (e.g., 2 + 3j).

        example-:
        x = 1
        y = 2.8
        z = 1j
        print(type(x))
        print(type(y))
        print(type(z))
      

      output is:

  2. Sequence Types:

    • str: String data type for text and characters (e.g., "Hello, World!").it is immutable. Data was stored in an ordered manner.

        example-:
        a = "Hello"
        print(a)
      

output is:

  • list: Ordered, mutable collection of items (e.g., [1, 2, 3]). It allows duplicate members. It can store any data type like str, set, tuple, or Dictionary. It is very flexible as the items in a list do not need to be of the same type.

      example-: list = ["apple", "banana", "cherry"] 
      print(list)
    

    output is:

  • tuple: Ordered, immutable collection of items (e.g., (1, 2, 3)). It stores any datatype like str, list, set,tuple. It allows duplicate members. The creation of a Python tuple without the use of parentheses is known as Tuple Packing.

      example-: tuple = ("apple", "banana", "cherry", "apple", "cherry")
      print(tuple)
    

    output is:

  1. Mapping Type:

    • dict: Dictionary data type for key-value pairs (e.g., {"key": "value"}). The dictionary datatype was mutable. data was stored in an unordered manner. It doesn't allow duplicate members. Inside of dictionary key can be int, str, or tuple only values can be of any data type int, str, list, tuple, set, or Dictionary.

      •   example-: 
          dict = {
            "brand": "Ford",
            "model": "Mustang",
            "year": 1964
          }
          print(dict["brand"])
        

        output is:

  1. Set Types:

    • set: Unordered collection of unique elements (e.g., {1, 2, 3}).set datatype was mutable. It doesn't allow duplicate members. It can store data types (int, str, tuple) but not (list, set, dictionary).

        example-: 
        set = {"apple", "banana", "cherry"}
        print(set)
      

      output is:

  2. Boolean Type:

    • bool: Represents either True or False.

        print(10 > 9) 
        print(10 == 9) 
        print(10 < 9)
      

Did you find this article valuable?

Support Achyut Das by becoming a sponsor. Any amount is appreciated!