Untitled Document
Untitled Document
Session: 2022-23
Conclusion: This Python program showcases operations on various data types, including
numeric, string, list, tuple, dictionary, and set. It demonstrates common operations like
accessing, updating, and manipulating data, providing a comprehensive overview of their
functionalities.
Program:
# Numeric Operations
# Addition
sum_nums = num_int + num_float
# Subtraction
sub_nums = num_int - num_float
# Multiplication
mul_nums = num_int * num_float
# Division
div_nums = num_int / num_float
# Modulo
mod_nums = num_int % 3
# Exponentiation
exp_nums = num_int ** 2
# String Operations
# Accessing character
access_char = my_string[0]
# Slicing
slicing = my_string[7:12]
# Indexing
indexing = my_string.index("W")
# Splitting
splitting = my_string.split(",")
# Concatenation
concatenation = my_string + "!!"
# List Operations
# Accessing element
access_element = my_list[2]
# Updating element
my_list[3] = 10
# Appending element
my_list.append(6)
# Inserting element
my_list.insert(1, 7)
# Popping element
popped_element = my_list.pop()
# Pushing element
my_list.append(8)
# Slicing
sliced_list = my_list[1:4]
# Length of list
list_length = len(my_list)
# Reversed list
list_reverse = list(reversed(my_list))
# Tuple Operations
# Accessing element
access_element_tuple = my_tuple[2]
# Length of tuple
tuple_length = len(my_tuple)
# Sum of tuple elements
tuple_sum = sum(my_tuple)
# Dictionary Operations
# Accessing value
access_value = my_dict["name"]
# Updating value
my_dict["age"] = 26
# Set Operations
# Checking membership
membership_check = 3 in my_set
# Adding element
my_set.add(6)
# Removing element
my_set.remove(3)
# Intersection of sets
set_intersection = my_set.intersection({2, 4, 6})
# Difference of sets
set_difference = my_set.difference({4, 5, 6})
Numeric Operations:
Sum: 13.14
Difference: 6.86
Product: 31.400000000000002
Division: 3.1847133757961785
Modulo: 1
Exponentiation: 100
String Operations:
Accessing character: H
Slicing: World
Indexing: 7
Splitting: ['Hello', ' World!']
Concatenation: Hello, World!!
Count substring: 3
List Operations:
Accessing element: 3
Updating element: [1, 2, 3, 10, 5]
Appending element: [1, 2, 3, 10, 5, 6]
Inserting element: [1, 7, 2, 3, 10, 5, 6]
Popping element: 6
Pushing element: [1, 7, 2, 3, 10, 5, 6, 8]
Slicing: [7, 2, 3]
Length of list: 7
Sum of list elements: 36
Reversed list: [8, 6, 5, 10, 3, 2, 1]
Tuple to list conversion: [1, 2, 3, 4, 5]
Tuple Operations:
Accessing element: 3
Length of tuple: 5
Sum of tuple elements: 15
Index of element: 3
List to tuple conversion: (1, 7, 2, 3, 10, 5, 6, 8)
Dictionary Operations:
Accessing value: John
Updating value: {'name': 'John', 'age': 26, 'gender': 'Male'}
Adding key-value pair: {'name': 'John', 'age': 26, 'gender': 'Male', 'city': 'New York'}
Deleting key-value pair: {'name': 'John', 'age': 26, 'gender': 'Male'}
Dictionary keys: dict_keys(['name', 'age', 'gender'])
Dictionary values: dict_values(['John', 26, 'Male'])
Dictionary items: dict_items([('name', 'John'), ('age', 26), ('gender', 'Male')])
Set Operations:
Membership check: False
Adding element: {1, 2, 4, 5, 6}
Removing element: {1, 2, 4, 5, 6}
Intersection of sets: {2, 6, 4}
Difference of sets: {1}