Python Data Types and Data Structures

Welcome to another day of learning! Today, we're learning about Python data types and data structures.

Data Types in Python:

Data types in Python classify data items and determine what operations can be performed on them. In Python, everything is an object, and data types are essentially classes.

Here are some built-in data types:
Numeric (Integer, Complex, Float)
Sequential (String, Lists, Tuples)
Boolean
Set
Dictionaries
To check the data type of a variable, you can use the type() function:

Data Structures:

Data structures organize data efficiently. In Python, learning about data structures is simpler than ever. Let's look at a few:

Lists:
Python Lists are ordered collections, similar to arrays in other languages. They're flexible, allowing different data types in a single list.
eg:- my_list = [1, 'Hello', 3.14, True]

Tuples:
Tuples are similar to lists but immutable. Once created, elements cannot be added or removed.
eg:- my_tuple = (1, 'World', 2.71, False)

Dictionary:
A Python dictionary is an unordered collection with key-value pairs, acting like hash tables in other languages.
eg:- my_dict = {"key1": "value1", "key2": "value2", "key3": "value3"}

Tasks:

1. Difference between List, Tuple, and Set:

Lists are ordered and mutable.
Tuples are ordered and immutable.
Sets are unordered and contain unique elements.

2. Dictionary Fun:

Created the fav_tools dictionary.
Used dictionary methods to print the favourite tool using keys.

Code:-

3. Cloud Providers List:

Created a list of cloud service providers.
Added "Digital Ocean" to the list and sorted it alphabetically.

Code:-

code for task 3

Did you find this article valuable?

Support DevOpsExplorer by becoming a sponsor. Any amount is appreciated!