Netbyzz

#B049

Python :

#CODE = #B049
# Example of List
print("List Example")
my_list = [1, 2, 3, 4, 5]
print("Original List:", my_list)

# Accessing elements
print("First Element:", my_list[0])

# Modifying elements
my_list[2] = 10
print("Modified List:", my_list)

# Iterating through a list
print("Iterating through List:")
for item in my_list:
    print(item)

print("\n")

# Example of Tuple
print("Tuple Example")
my_tuple = (1, 2, 3, 4, 5)
print("Original Tuple:", my_tuple)

# Accessing elements
print("First Element:", my_tuple[0])

# Tuples are immutable, so you can't modify them directly
# my_tuple[2] = 10 # This would raise an error

# Iterating through a tuple
print("Iterating through Tuple:")
for item in my_tuple:
    print(item)

print("\n")

# Example of Set
print("Set Example")
my_set = {1, 2, 3, 4, 5}
print("Original Set:", my_set)

# Adding elements
my_set.add(6)
print("Set after adding an element:", my_set)

# Removing elements
my_set.remove(2)
print("Set after removing an element:", my_set)

# Iterating through a set
print("Iterating through Set:")
for item in my_set:
    print(item)

print("\n")

# Example of Dictionary
print("Dictionary Example")
my_dict = {"name": "Alice", "age": 25, "city": "New York"}
print("Original Dictionary:", my_dict)

# Accessing elements
print("Name:", my_dict["name"])

# Modifying elements
my_dict["age"] = 30
print("Modified Dictionary:", my_dict)

# Adding new key-value pairs
my_dict["job"] = "Engineer"
print("Dictionary after adding a new key-value pair:", my_dict)

# Iterating through a dictionary
print("Iterating through Dictionary:")
for key, value in my_dict.items():
    print(key, ":", value)

Source Code