What is Python?
Python is Open source, general purpose, high-level, and object-oriented programming language. Python has a simple syntax and it is easy to learn, Python has a rich collection of libraries and modules. Python is an important programming language for DevOps engineers as it provides a wide range of tools and libraries for automating various tasks and building robust infrastructure.
To install Python on Ubuntu, follow these steps:
Update the package list and upgrade the system by running the following command:
sudo apt update
sudo apt upgrade
Install Python by using the below command:
sudo apt install python3
To check the version of Python installed in our system:
python3 --version
Different Data Types in Python
Below are the most commonly used data type in Python,
List: A list is an ordered collection of values that is separated by commas. Lists in Python are mutable, which means you can add, remove, or modify elements in a list after it has been created
Examples, ["Apple", "Samsung", "Redmi"].
Tuple: A tuple is an ordered, immutable collection of values, enclosed in parentheses and separated by commas. You cannot add, remove, or modify elements in a tuple once it has been created
Examples, ("Apple", "Samsung", "Redmi").
Set: A set is an unordered collection of unique values, enclosed in curly braces and separated by commas.
Examples, {"Apple", "Samsung", "Redmi"}.
Dictionary: A dictionary is an unordered collection of key-value pairs, enclosed in curly braces and separated by commas.
Examples, {"name": "Rohit", "age": 40}
Tasks
Give the Difference between List, Tuple and Set.
Lists and sets are mutable, meaning you can add, remove, or modify elements after the data type has been created. This makes them suitable for situations where you need to modify the contents of a collection frequently.
Tuples, on the other hand, are immutable, which means that once a tuple is created, its contents cannot be changed. Tuples are useful when you need to ensure that the contents of a collection cannot be modified.
Lists and tuples are ordered, which means that the elements in the data type have a specific order and can be accessed by their index. Sets, on the other hand, are unordered, which means that the elements in the data type have no specific order.
Lists and tuples can contain duplicate elements, while sets only contain unique elements.
Create the below Dictionary and use Dictionary methods to print your favourite tool just by using the keys of the Dictionary.
fav_tools = { 1:"Linux", 2:"Git", 3:"Docker", 4:"Kubernetes", 5:"Terraform", 6:"Ansible", 7:"Chef" }
Create a List of cloud service providers,
ex. cloud_providers = ["AWS","GCP","Azure"]
Write a program to add
Digital Ocean
to the list of cloud_providers and sort the list in alphabetical order.
Without using the sort function below is the code,
cloud_providers = ["AWS", "GCP", "Azure"]
cloud_providers.append("Digital Ocean")
sorted_providers = [] while cloud_providers: min_provider = cloud_providers[0] for provider in cloud_providers: if provider < min_provider: min_provider = provider sorted_providers.append(min_provider) cloud_providers.remove(min_provider)
print(sorted_providers)
Thank you for reading the blog.
Suggestions are always welcome. Thank you !!