Day13: Basics of Python For DevOps

90DaysOfDevOps

·

3 min read

Day13: Basics of Python For DevOps

After learning basic Linux and Git-GitHub commands, let's start with the Basics of Python as this is also important for DevOps Engineers to build the logic and programs.

What is Python?

Python is a high-level, versatile, and interpreted programming language. It was created by Guido van Rossum and was first released in 1991. Python emphasizes readability and ease of use, making it a popular choice for beginners and experienced programmers.

Python is widely used in various domains, including web development, scientific computing, data analysis, artificial intelligence, machine learning, automation, and more.

Key features of Python include:

  1. Readability

  2. Versatility

  3. Extensive Standard Library

  4. Interpreted

  5. Cross-platform

  6. Dynamic Typing

  7. Community and Ecosystem

  8. Open Source

How to Install Python?

You can install Python in your System whether it is window, MacOS, ubuntu, centos etc.

To install Python on your computer, follow these general steps:

  1. Choose a Version: First, decide whether you want to install Python 2 or Python 3. Python 3 is recommended, as Python 2 has reached its end of life. This means that Python 2 will no longer receive official updates and support.

  2. Download the Installer: Visit the official Python website to download the installer for your operating system. The website is python.org. On the homepage, you'll find a "Downloads" section. Click on it.

  3. Select the Installer: Choose the installer that matches your operating system. For Windows, you'll likely download an executable installer (.exe). For macOS and Linux, you might download a package or use a package manager.

  4. Run the Installer:

    • Windows: Double-click the downloaded .exe file and follow the installation prompts. Make sure to check the box that says "Add Python X.X to PATH" during installation, as this will allow you to use Python from the command prompt.

    • macOS: Open the downloaded package and follow the installation instructions.

    • Linux: Depending on your distribution, you might use the package manager. For example, on Ubuntu, you can use the terminal and run sudo apt-get install python3 to install Python 3.

  5. Verify Installation: After installation, open a command prompt or terminal and type python or python3 (depending on your system) and press Enter. You should see the Python interpreter prompt, indicating that Python is installed and running. You can exit the interpreter by typing exit().

Task1:

Install Python in your respective OS, and check the version.

I Installed Python on my PC On Windows (using Chocolatey)

Here is the command:

choco install python

Here you can see the installed version on my computer below

Read about different Data Types in Python.

Python supports several built-in data types that are used to represent different kinds of values. Here are some of the common data types in Python:

  1. Numeric Types:

    • int: Represents integer values, e.g., 5, -12, 1000.

    • float: Represents floating-point (decimal) values, e.g., 3.14, -0.5, 2.0.

  2. Text Type:

    • str: Represents strings, which are sequences of characters enclosed in single, double, or triple quotes, e.g., "Hello, world!", 'Python', '''Multiline string'''.
  3. Boolean Type:

    • bool: Represents boolean values, which can be either True or False.
  4. Sequence Types:

    • list: Represents ordered and mutable collections of items. Lists are defined using square brackets, e.g., [1, 2, 3].

    • tuple: Represents ordered and immutable (cannot change) collections of items. Tuples are defined using parentheses, e.g., (1, 2, 3).

  5. Mapping Type:

    • dict: Represents key-value pairs in an unordered collection. Dictionaries are defined using curly braces and colons, e.g., {'key1': 'value1', 'key2': 'value2'}.
  6. Set Types:

    • set: Represents an unordered collection of unique elements. Sets are defined using curly braces, e.g., {1, 2, 3}.

Now, that we have installed Python in our system, we will study more on variables and data types and data structures tomorrow.

Stay tuned!

Happy Learning!