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

Question 2 Answer Clean

Uploaded by

hhabibulla344
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 views2 pages

Question 2 Answer Clean

Uploaded by

hhabibulla344
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/ 2

Question 2: Write a program to demonstrate working with tuples in Python

Aim:

To write a Python program that demonstrates the creation, accessing elements, and basic

operations on tuples.

Algorithm:

1. Start the program.

2. Create a tuple with multiple elements.

3. Access elements using indexing.

4. Perform slicing operations on the tuple.

5. Demonstrate basic tuple operations like concatenation and repetition.

6. Print the tuple after each operation to show the results.

7. End the program.

Python Code:

my_tuple = (10, 20, 30, 40, 50)

print("Original Tuple:", my_tuple)

print("Element at index 1:", my_tuple[1])

print("Slice of the tuple (index 1 to 3):", my_tuple[1:4])

new_tuple = my_tuple + (60, 70)

print("After concatenation:", new_tuple)

repeated_tuple = my_tuple * 2
print("After repetition:", repeated_tuple)

Sample Output:

Original Tuple: (10, 20, 30, 40, 50)

Element at index 1: 20

Slice of the tuple (index 1 to 3): (20, 30, 40)

After concatenation: (10, 20, 30, 40, 50, 60, 70)

After repetition: (10, 20, 30, 40, 50, 10, 20, 30, 40, 50)

You might also like