Day 13: Basics Of Python

Day 13: Basics Of Python

Python:

Python is a high-level, interpreted programming language. It was created by Guido van Rossum.

Python is famous for being easy to use, having a robust standard library, and dynamic semantics.

The main goal behind its creation is to make it simpler for developers to read and grasp, and also reduce the lines of code. It helps in organizing code step by step. It's like having a toolbox full of different tools for solving problems with your computer!

It has a large community of developers who keep contributing towards its growth.

What is the need for Python in DevOps?

In DevOps, Python is often used for scripting automation tasks, building tools for infrastructure management, and integrating with various DevOps tools and frameworks. Its simplicity and versatility make it a popular choice among DevOps engineers and practitioners.

How to install Python?

For Windows:

Step 1: Visit the website https://www.python.org and click on downloads.

Step 2: Click on download python so that you can directly download the recent version.

Step 3: After completion of downloading launch the installer and select the checkbox of Add python.exe to PATH and click on the install now button. you can also customize your installation location. After that select the yes button to allow the changes to your system so that setup progresses.

Step 4: If you download it for the first time it will ask for optional features for the installation otherwise it will directly jump to step 6. Click next to move to the advance option screen.

Step 5: Select the advanced options and click on the install button.

Step 6: It will show the installation pogress.

Step 7: You can click on the disable path length limit so that it can bypass the MAX_PATH limit or you can directly close it.

Step 8: After bypassing you can see a setup was successful screen and after that click on the close button.

Step 9: Open the cmd terminal and verify that Python's latest version is installed in your system or not.

python --version command will give the latest version of Python installed on your system.

For Ubuntu:

Multiple methods to download python3 on Ubuntu I suggest the easy one.

Step 1: Before downloading, first check if python3 is installed on your machine or not. Open the terminal and run the command python3 . It will tell you about the version of python3 installed on your machine.

Step 2: We will download using apt. Run the command sudo apt update so that it can update the package repository to download the latest version.

Step 3: After updating install Python using the command sudo apt install python3

Step 4: After that verify using python3 --verion to check the latest version you downloaded.

Python Data Types

Numeric data types: It represent the numeric value of data.

  1. Integer: Its value is represented by int class. It contains positive or negative whole numbers. For example 100, -5, 255.

  2. Float: Its value is represented by the float class. It contains a real number. It is specified by a decimal point and it can be accurate within 15 decimal places. For example: 2.5, 2.8

  3. complex number: Its value is represented by a complex class. It is the combination of "real value + imaginary value". For example 1+2j, 70+230j

Sequence data types: It represent the data in sequential order.

  1. String: It represents the sequence of characters enclosed by single quotes(' ') or double quotes(" "). For example: 'data', 'name', "cat".

  2. List: Lists are ordered collections of items, which can be of different data types. It can be modified after creation. For example: [1,2,3,4,5,6]

  3. Tuple: It is used to represent a fixed collection of items. Its duplicate value can be present. It can not be modified once we create it. For example: (1,2,2,4,4,6)

  4. Boolean: It is used to represent the boolean value which can be either "True" or "False". It is used for logical operation and condition.

  5. Dictionary: It is used for unordered collections of key-value pairs. Each key in a dictionary must be unique and associated with a value. For example: {'name': 'XYZ', 'age': 20, 'roll no': 14}

  6. Set: It is used for an unordered collection of unique items. It does not allow duplicate items. For example: {1,2,3,}, {'apple', 'banana', 'pineapple'}.

Summary

In this blog, we learn the basics of Python and how it is useful as a DevOps engineer. As Python helps DevOps engineers work smarter and more efficiently. After that learn the installation of Python in Windows and Ubuntu systems. In the last, we learn data types in Python.