0% found this document useful (0 votes)
21 views3 pages

Document From AVK

Uploaded by

ashu23kanojia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Document From AVK

Uploaded by

ashu23kanojia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT NO.

05

Name : Swatantra Kasliwal


ID : VU4F2223035
Batch : B SE/IT/A

AIM : Write Python programs to implement Tuples operation using built-in function.

Theory :
Tuple is a collection of Python objects much like a list. The sequence of values stored in a tuple
can be of any type, and they are indexed by integers.
Tuples are defined using parentheses ()
#Concation
concat_tuple = tuple1 + tuple2
print("Concatenation:", concat_tuple)
# Repetition
repeat_tuple = tuple1 * 3
print("Repetition:", repeat_tuple)
# Length of tuple
length = len(tuple1)
print("Length:", length)
# Membership test
is_member = 4 in tuple1
print("Membership test:", is_member)
# Accessing elements
element = tuple1[1]
print("Accessing element at index 1:", element)
# Slicing
sliced_tuple = tuple2[1:]
print("Sliced tuple:", sliced_tuple)
# Minimum and maximum elements
min_element = min(tuple1)
max_element = max(tuple1)
print("Minimum element:", min_element)
print("Maximum element:", max_element)
# Convert tuple to list
tuple_list = list(tuple1)
print("Converted to list:", tuple_list)

# Count occurrences
count_occurrences = tuple1.count(2)
print("Count of occurrences of 2:", count_occurrences)
# Index of element
index_of_element = tuple1.index(3)
print("Index of element 3:", index_of_element)

PROGRAM :
# Creating tuples
tuple1 = (1, 2, 3)
tuple2 = (4, 5, 6)
# Concatenation
concat_tuple = tuple1 + tuple2
print("Concatenation:", concat_tuple)
# Repetition
repeat_tuple = tuple1 * 3
print("Repetition:", repeat_tuple)
# Length of tuple
length = len(tuple1)
print("Length:", length)
# Membership test
is_member = 4 in tuple1
print("Membership test:", is_member)
# Accessing elements
element = tuple1[1]
print("Accessing element at index 1:", element)
# Slicing
sliced_tuple = tuple2[1:]
print("Sliced tuple:", sliced_tuple)
# Minimum and maximum elements
min_element = min(tuple1)
max_element = max(tuple1)
print("Minimum element:", min_element)
print("Maximum element:", max_element)
# Convert tuple to list
tuple_list = list(tuple1)
print("Converted to list:", tuple_list)
# Count occurrences
count_occurrences = tuple1.count(2)
print("Count of occurrences of 2:", count_occurrences)
# Index of element
index_of_element = tuple1.index(3)
print("Index of element 3:", index_of_element)

You might also like