Install Python on Ubuntu:
To install Python on Ubuntu, you can follow these steps:
Open a terminal on your Ubuntu machine by pressing
Ctrl + Alt + T
on your keyboard.Type the following command to update the package lists:
sudo apt update
Then, type the following command to install Python:
sudo apt install python3
- Once the installation is complete, verify the installation by running the following command:
python3 --version
TASK-1 Understanding the Differences between List, Tuple, and Set:
List: Lists are ordered, mutable collections of elements in Python. They are defined using square brackets
[ ]
. Elements can be added, removed, or modified from the list.Here's an example of creating a list of fruits:
fruits = ['apple', 'banana', 'orange']
Tuple: Tuples are ordered, immutable collections of elements in Python. They are defined using parentheses
( )
. Elements cannot be added, removed, or modified from the tuple.Here's an example of creating a tuple of colours:
colors = ('red', 'green', 'blue')
Set: Sets are unordered, mutable collections of unique elements in Python. They are defined using curly braces
{ }
. Elements can be added or removed from the set, but not modified.Here's an example of creating a set of numbers:
numbers = {1, 2, 3, 4, 5}
TASK-2 Create the below Dictionary and use Dictionary methods to print your favourite tool just by using the keys of the Dictionary:
here, what I have done is create a Dictionary and print my key value for a favourite tool like "docker".
- I execute it and it returns with "My favourite tool is Docker"
TASK-3 -Create a List of cloud service providers eg.
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.
Step-1 Create a file with extension .py and add the code :/
cloud_providers = ["AWS","GCP","Azure"]
cloud_providers.append("Digital Ocean")
cloud_providers.sort()
print(cloud_providers)
In this, I have to append " Digital ocean " in cloud_provider and sort it in alphabetical order.
Now Execute it with python3 :
Result: Digital Ocean is appended to it and gets sorted Alphabetically!!!!!!
Thanks: