-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
A tuple is a collection which is ordered and unchangeable.
Tuples are written with round brackets ()
.
fruits = ("apple", "banana", "cherry")
print(fruits)
Tuples keep the order in which items are added.
print(fruits[1]) # banana
print(fruits[-1]) # cherry
print(len(fruits)) # 3
Add a comma ,
to create a tuple with one item.
single = ("apple",)
print(type(single)) # <class 'tuple'>
mixed = ("apple", 5, True)
t = tuple(("a", "b", "c"))
for item in fruits:
print(item)
if "banana" in fruits:
print("Yes")
Tuples are unchangeable. Convert to list → change → convert back.
x = ("apple", "banana", "cherry")
temp = list(x)
temp[1] = "orange"
x = tuple(temp)
print(x)
a = (1, 2)
b = (3, 4)
c = a + b
Create and access tuples, check membership, and combine tuples.
Q1. Write a Python program to create a tuple of 5 programming languages and print it.
Q2. Write a Python program to print the second item of a tuple.
Q3. Write a Python program to print the last item of a tuple using negative indexing.
Q4. Write a Python program to check if "Java"
exists in a tuple using the in
keyword.
Q5. Write a Python program to convert a tuple to a list, change a value, and print the updated list.
Q6. Write a Python program to create a tuple with only one item and print its type.
Q7. Write a Python program to join two tuples together and print the result.
Q8. Write a Python program to loop through a tuple using a for
loop and print each item.
Q9. Write a Python program to find the length of a tuple using the len()
function.
Q10. Write a Python program to create a tuple with mixed data types (e.g., int, string, float) and print it.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms