Greetings DevOps enthusiasts! Today on our journey, let's dive into the Python world of Data Types and Structures. ππ‘
Data Types in Python: ππ’
In Python, data types classify items and determine the operations we can perform on them. Whether it's Numeric, Sequential, Boolean, or others, Python's got it all! π’π
In Python, data types classify the type of values that variables can hold. Let's explore a few:
Numeric Types:
Integer (int): Whole numbers without decimals. Example:
age = 25
Float (float): Numbers with decimals. Example:
price = 19.99
Complex (complex): Numbers in the form
a + bj
, wherea
andb
are floats. Example:z = 3 + 5j
Sequential Types:
String (str): Ordered sequences of characters. Example:
name = "John"
List (list): Ordered, mutable collections. Example:
fruits = ["apple", "banana", "orange"]
Tuple (tuple): Ordered, immutable collections. Example:
coordinates = (10, 20)
Boolean Type:
- Boolean (bool): Represents
True
orFalse
. Example:is_devops = True
- Boolean (bool): Represents
Set Type:
- Set (set): Unordered collections of unique elements. Example:
unique_numbers = {1, 2, 3, 4}
- Set (set): Unordered collections of unique elements. Example:
Dictionary Type:
- Dictionary (dict): Unordered key-value pairs. Example:
student = {"name": "Alice", "age": 21}
- Dictionary (dict): Unordered key-value pairs. Example:
Data Structures in Python: π¦ΈββοΈπ¦ΈββοΈ
Think of these as the organizational superheroes of data. Lists, Tuples, and Dictionaries play key roles. Lists are flexible arrays, Tuples are immutable collections, and Dictionaries are optimized key-value pairs. π¦ΈββοΈπ¦ΈββοΈ
Data structures organize and store data efficiently. Let's look at a few:
List: π
Ordered, mutable collection.
Example:
languages = ["Python", "JavaScript", "Java"]
Tuple: π¦
Ordered, immutable collection.
Example:
dimensions = (10, 20, 15)
Dictionary: π
Unordered key-value pairs.
Example:
book = {"title": "Python Crash Course", "author": "Eric Matthes"}